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
-
#context_target ⇒ Object
Returns the value of attribute context_target.
-
#value_formatter ⇒ Object
Returns the value of attribute value_formatter.
Instance Method Summary collapse
- #complete(value) ⇒ Object
- #default_conversion_block ⇒ Object
- #default_value ⇒ Object
- #format_description ⇒ Object
- #help_lhs ⇒ Object
- #help_rhs ⇒ Object
- #value_description ⇒ Object
Instance Attribute Details
#context_target ⇒ Object
Returns the value of attribute context_target.
22 23 24 |
# File 'lib/hammer_cli/options/option_definition.rb', line 22 def context_target @context_target end |
#value_formatter ⇒ Object
Returns the value of attribute value_formatter.
21 22 23 |
# File 'lib/hammer_cli/options/option_definition.rb', line 21 def value_formatter @value_formatter end |
Instance Method Details
#complete(value) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/hammer_cli/options/option_definition.rb', line 24 def complete(value) if value_formatter.nil? [] else value_formatter.complete(value) end end |
#default_conversion_block ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/hammer_cli/options/option_definition.rb', line 67 def default_conversion_block if !value_formatter.nil? value_formatter.method(:format) elsif flag? Clamp.method(:truthy?) end end |
#default_value ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/hammer_cli/options/option_definition.rb', line 75 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
47 48 49 50 51 52 53 |
# File 'lib/hammer_cli/options/option_definition.rb', line 47 def format_description if value_formatter.nil? "" else value_formatter.description end end |
#help_lhs ⇒ Object
32 33 34 |
# File 'lib/hammer_cli/options/option_definition.rb', line 32 def help_lhs super end |
#help_rhs ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/hammer_cli/options/option_definition.rb', line 36 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
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/hammer_cli/options/option_definition.rb', line 55 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 |