Class: EacCli::Definition::BaseOption
- Inherits:
-
Object
- Object
- EacCli::Definition::BaseOption
show all
- Includes:
- DefaultValue
- Defined in:
- lib/eac_cli/definition/base_option.rb,
lib/eac_cli/definition/base_option/initialize_args_parser.rb
Defined Under Namespace
Classes: InitializeArgsParser
Constant Summary
collapse
- DEFAULT_REQUIRED =
false
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.from_args(args) ⇒ Object
13
14
15
16
|
# File 'lib/eac_cli/definition/base_option.rb', line 13
def from_args(args)
p = ::EacCli::Definition::BaseOption::InitializeArgsParser.new(args)
new(p.short, p.long, p.description, p.options)
end
|
Instance Method Details
#default_value ⇒ Object
32
33
34
|
# File 'lib/eac_cli/definition/base_option.rb', line 32
def default_value
default_value? ? options[OPTION_DEFAULT] : default_default_value
end
|
#default_value? ⇒ Boolean
36
37
38
|
# File 'lib/eac_cli/definition/base_option.rb', line 36
def default_value?
options.key?(OPTION_DEFAULT)
end
|
#identifier ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/eac_cli/definition/base_option.rb', line 40
def identifier
[long, short].each do |v|
v.to_s.if_present { |vv| return vv.variableize.to_sym }
end
raise(::EacCli::Definition::Error, 'No short or long option to build identifier')
end
|
#repeat? ⇒ Boolean
48
49
50
|
# File 'lib/eac_cli/definition/base_option.rb', line 48
def repeat?
options[OPTION_REPEAT]
end
|
#required? ⇒ Boolean
52
53
54
55
56
57
|
# File 'lib/eac_cli/definition/base_option.rb', line 52
def required?
return true if options.key?(:required) && options.fetch(:required)
return false if options.key?(:optional) && options.fetch(:optional)
DEFAULT_REQUIRED
end
|
#show_on_usage? ⇒ Boolean
63
64
65
|
# File 'lib/eac_cli/definition/base_option.rb', line 63
def show_on_usage?
options[:usage]
end
|
59
60
61
|
# File 'lib/eac_cli/definition/base_option.rb', line 59
def to_s
"#{self.class.name.demodulize}[#{identifier}]"
end
|