Class: HammerCLI::Options::OptionDefinition
- Inherits:
-
Clamp::Option::Definition
- Object
- Clamp::Option::Definition
- HammerCLI::Options::OptionDefinition
- Defined in:
- lib/hammer_cli/options/option_definition.rb
Direct Known Subclasses
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
-
#initialize(switches, type, description, options = {}) ⇒ OptionDefinition
constructor
A new instance of OptionDefinition.
- #value_description ⇒ Object
Constructor Details
#initialize(switches, type, description, options = {}) ⇒ OptionDefinition
Returns a new instance of OptionDefinition.
24 25 26 27 28 |
# File 'lib/hammer_cli/options/option_definition.rb', line 24 def initialize(switches, type, description, = {}) self.value_formatter = .delete(:format) self.context_target = .delete(:context_target) super end |
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
30 31 32 33 34 35 36 |
# File 'lib/hammer_cli/options/option_definition.rb', line 30 def complete(value) if value_formatter.nil? [] else value_formatter.complete(value) end end |
#default_conversion_block ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/hammer_cli/options/option_definition.rb', line 73 def default_conversion_block if !value_formatter.nil? value_formatter.method(:format) elsif flag? Clamp.method(:truthy?) end end |
#default_value ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/hammer_cli/options/option_definition.rb', line 81 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
53 54 55 56 57 58 59 |
# File 'lib/hammer_cli/options/option_definition.rb', line 53 def format_description if value_formatter.nil? "" else value_formatter.description end end |
#help_lhs ⇒ Object
38 39 40 |
# File 'lib/hammer_cli/options/option_definition.rb', line 38 def help_lhs super end |
#help_rhs ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/hammer_cli/options/option_definition.rb', line 42 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
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/hammer_cli/options/option_definition.rb', line 61 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 |