Class: HammerCLI::Options::OptionDefinition
- Inherits:
-
Clamp::Option::Definition
- Object
- Clamp::Option::Definition
- HammerCLI::Options::OptionDefinition
- Defined in:
- lib/hammer_cli/options/option_definition.rb
Instance Attribute Summary collapse
-
#value_formatter ⇒ Object
Returns the value of attribute value_formatter.
Instance Method Summary collapse
- #default_conversion_block ⇒ Object
- #default_value ⇒ Object
- #format_description ⇒ Object
- #help_lhs ⇒ Object
- #help_rhs ⇒ Object
- #value_description ⇒ Object
Instance Attribute Details
#value_formatter ⇒ Object
Returns the value of attribute value_formatter.
8 9 10 |
# File 'lib/hammer_cli/options/option_definition.rb', line 8 def value_formatter @value_formatter end |
Instance Method Details
#default_conversion_block ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/hammer_cli/options/option_definition.rb', line 45 def default_conversion_block if !value_formatter.nil? value_formatter.method(:format) elsif flag? Clamp.method(:truthy?) end end |
#default_value ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/hammer_cli/options/option_definition.rb', line 53 def default_value if defined?(@default_value) if value_formatter value_formatter.format(@default_value) else @default_value end elsif multivalued? [] end end |
#format_description ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/hammer_cli/options/option_definition.rb', line 25 def format_description if value_formatter.nil? "" else value_formatter.description end end |
#help_lhs ⇒ Object
10 11 12 |
# File 'lib/hammer_cli/options/option_definition.rb', line 10 def help_lhs super end |
#help_rhs ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/hammer_cli/options/option_definition.rb', line 14 def help_rhs lines = [ description.strip, format_description.strip, value_description.strip ] rhs = lines.reject(&:empty?).join("\n") rhs.empty? ? " " : rhs end |
#value_description ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/hammer_cli/options/option_definition.rb', line 33 def value_description default_sources = [ ("$#{@environment_variable}" if defined?(@environment_variable)), (@default_value.inspect if defined?(@default_value)) ].compact str = "" str += "Can be specified multiple times. " if multivalued? str += "Default: " + default_sources.join(", or ") unless default_sources.empty? str end |