Class: MGit::ARGV::Opt
- Inherits:
-
Object
- Object
- MGit::ARGV::Opt
- Defined in:
- lib/m-git/argv/opt.rb
Overview
单个选项, 如‘–k1=v1 –k2 v2 v3 –flag’ ‘–k1=v1’ key: ‘–k1’, value: ‘v1’ ‘–k2 v2 v3’ key: ‘–k2’, value: [‘v2’, ‘v3’] ‘–flag’ key: ‘–flag’, value: true
Instance Attribute Summary collapse
-
#info ⇒ Object
参数说明.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#priority ⇒ Object
参数解析优先级.
-
#short_key ⇒ Object
短参数格式,如’–command’对应的‘-c’.
-
#value ⇒ Object
Returns the value of attribute value.
-
#value_type ⇒ Object
:array :string :boolean.
-
#value值类型 ⇒ Object
:array :string :boolean.
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(key, default: nil, short_key: nil, priority: -1,, info: nil, type: :array) ⇒ Opt
constructor
A new instance of Opt.
- #validate? ⇒ Boolean
Constructor Details
#initialize(key, default: nil, short_key: nil, priority: -1,, info: nil, type: :array) ⇒ Opt
Returns a new instance of Opt.
21 22 23 24 25 |
# File 'lib/m-git/argv/opt.rb', line 21 def initialize(key, default:nil, short_key:nil, priority:-1, info:nil, type: :array) raise("初始化Opt选项必须有key") if key.nil? @key, @value, @short_key, @priority, @info = key, default, short_key, priority, info @value_type = type end |
Instance Attribute Details
#info ⇒ Object
参数说明
15 16 17 |
# File 'lib/m-git/argv/opt.rb', line 15 def info @info end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
11 12 13 |
# File 'lib/m-git/argv/opt.rb', line 11 def key @key end |
#priority ⇒ Object
参数解析优先级
14 15 16 |
# File 'lib/m-git/argv/opt.rb', line 14 def priority @priority end |
#short_key ⇒ Object
短参数格式,如’–command’对应的‘-c’
13 14 15 |
# File 'lib/m-git/argv/opt.rb', line 13 def short_key @short_key end |
#value ⇒ Object
Returns the value of attribute value.
12 13 14 |
# File 'lib/m-git/argv/opt.rb', line 12 def value @value end |
#value_type ⇒ Object
:array :string :boolean
19 20 21 |
# File 'lib/m-git/argv/opt.rb', line 19 def value_type @value_type end |
#value值类型 ⇒ Object
:array :string :boolean
19 |
# File 'lib/m-git/argv/opt.rb', line 19 attr_accessor :value_type |
Instance Method Details
#empty? ⇒ Boolean
27 28 29 |
# File 'lib/m-git/argv/opt.rb', line 27 def empty? value.nil? || value == '' || value == [] || value == false end |
#validate? ⇒ Boolean
31 32 33 34 |
# File 'lib/m-git/argv/opt.rb', line 31 def validate? return false if empty? value.is_a?(value_type) end |