class MGit::ARGV::OptList

参数对象列表

Attributes

opts[RW]
Array<ARGV::Opt>

参数对象数组

Public Class Methods

new(opts) click to toggle source

attr_reader :valid_opts

# File lib/m-git/argv/opt_list.rb, line 13
def initialize(opts)
  @opts = opts
end

Public Instance Methods

did_register_opt?(key) click to toggle source

判断参数是否注册过

@return [Boolean] 参数是否注册过

# File lib/m-git/argv/opt_list.rb, line 56
def did_register_opt?(key)
  !registered_opt(key).nil?
end
did_set_opt?(key) click to toggle source

判断参数是否设置过值

@return [Boolean] 参数是否设置过值

# File lib/m-git/argv/opt_list.rb, line 36
def did_set_opt?(key)
  !opt(key).nil?
end
opt(key) click to toggle source

获取某个参数对象

@param key [String] 参数名,如‘–key’

@return [ARGV::Opt] 参数对象,若参数未设置过则返回nil

# File lib/m-git/argv/opt_list.rb, line 27
def opt(key)
  valid_opts.find { |e| (e.key == key || e.short_key == key) }
end
Also aliased as: opt_with
opt_with(key)
Alias for: opt
opts_ordered_by_priority() click to toggle source

将参数根据优先级排序(逆序)后返回

@return [Array<ARGV::Opt>] 包含参数对象的数组

# File lib/m-git/argv/opt_list.rb, line 64
def opts_ordered_by_priority
  # 按照优先级进行降序排序
  opts.sort_by { |e| e.priority }.reverse
end
registered_opt(key) click to toggle source

返回某个注册过的参数对象

@param key [String] 参数名,如‘–key’

@return [ARGV::Opt] 参数对象,无论参数是否设置过,只要注册过就返回

# File lib/m-git/argv/opt_list.rb, line 48
def registered_opt(key)
  @opts.find { |e| (e.key == key || e.short_key == key) }
end
valid_opts() click to toggle source
# File lib/m-git/argv/opt_list.rb, line 17
def valid_opts
  @opts.select { |e| !e.empty? }
end