Class: UltraCommandLine::Commands::OptionDefinition
- Inherits:
-
Object
- Object
- UltraCommandLine::Commands::OptionDefinition
- Defined in:
- lib/ultra_command_line/commands/option_definition.rb
Constant Summary collapse
- DEFAULT_SUMMARY =
'Option summary not provided.'.freeze
Instance Attribute Summary collapse
-
#default ⇒ Object
Returns the value of attribute default.
-
#dependencies ⇒ Object
Returns the value of attribute dependencies.
-
#description ⇒ Object
Returns the value of attribute description.
-
#help ⇒ Object
Returns the value of attribute help.
-
#incompatibilities ⇒ Object
Returns the value of attribute incompatibilities.
-
#long_aliases ⇒ Object
Returns the value of attribute long_aliases.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#short_aliases ⇒ Object
Returns the value of attribute short_aliases.
-
#summary ⇒ Object
Returns the value of attribute summary.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #global? ⇒ Boolean
- #help_line(slop_options = UltraCommandLine.new_slop_options) ⇒ Object
-
#initialize(name, type, options = {}) ⇒ OptionDefinition
constructor
A new instance of OptionDefinition.
- #to_slop_options(slop_options = UltraCommandLine.new_slop_options) ⇒ Object
Constructor Details
#initialize(name, type, options = {}) ⇒ OptionDefinition
Returns a new instance of OptionDefinition.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ultra_command_line/commands/option_definition.rb', line 11 def initialize(name, type, = {}) @name = name @type = type @summary = .fetch(:summary, DEFAULT_SUMMARY) @default = .fetch(:default, nil) @description = .fetch(:description, summary) @help = .fetch(:help, description) @global = .fetch(:global, false) @dependencies = .fetch(:dependencies, []) self.dependencies = dependencies.is_a?(Array) ? dependencies : [dependencies] @incompatibilities = .fetch(:incompatibilities, []) self.incompatibilities = incompatibilities.is_a?(Array) ? incompatibilities : [incompatibilities] short_aliases = .fetch(:short_aliases, []) long_aliases = .fetch(:long_aliases, []) self.short_aliases = (short_aliases.is_a?(Array) ? short_aliases : [short_aliases]).map &:to_sym self.long_aliases = (long_aliases.is_a?(Array) ? long_aliases : [long_aliases]).map &:to_sym end |
Instance Attribute Details
#default ⇒ Object
Returns the value of attribute default.
9 10 11 |
# File 'lib/ultra_command_line/commands/option_definition.rb', line 9 def default @default end |
#dependencies ⇒ Object
Returns the value of attribute dependencies.
9 10 11 |
# File 'lib/ultra_command_line/commands/option_definition.rb', line 9 def dependencies @dependencies end |
#description ⇒ Object
Returns the value of attribute description.
9 10 11 |
# File 'lib/ultra_command_line/commands/option_definition.rb', line 9 def description @description end |
#help ⇒ Object
Returns the value of attribute help.
9 10 11 |
# File 'lib/ultra_command_line/commands/option_definition.rb', line 9 def help @help end |
#incompatibilities ⇒ Object
Returns the value of attribute incompatibilities.
9 10 11 |
# File 'lib/ultra_command_line/commands/option_definition.rb', line 9 def incompatibilities @incompatibilities end |
#long_aliases ⇒ Object
Returns the value of attribute long_aliases.
8 9 10 |
# File 'lib/ultra_command_line/commands/option_definition.rb', line 8 def long_aliases @long_aliases end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/ultra_command_line/commands/option_definition.rb', line 7 def name @name end |
#short_aliases ⇒ Object
Returns the value of attribute short_aliases.
8 9 10 |
# File 'lib/ultra_command_line/commands/option_definition.rb', line 8 def short_aliases @short_aliases end |
#summary ⇒ Object
Returns the value of attribute summary.
9 10 11 |
# File 'lib/ultra_command_line/commands/option_definition.rb', line 9 def summary @summary end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/ultra_command_line/commands/option_definition.rb', line 7 def type @type end |
Instance Method Details
#global? ⇒ Boolean
44 45 46 |
# File 'lib/ultra_command_line/commands/option_definition.rb', line 44 def global? @global end |
#help_line(slop_options = UltraCommandLine.new_slop_options) ⇒ Object
61 62 63 |
# File 'lib/ultra_command_line/commands/option_definition.rb', line 61 def help_line( = UltraCommandLine.) ().to_s.gsub /\n/, '' end |
#to_slop_options(slop_options = UltraCommandLine.new_slop_options) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ultra_command_line/commands/option_definition.rb', line 48 def ( = UltraCommandLine.) = short_aliases.map.each { |option| "-#{option}" } = long_aliases.map.each { |option| "--#{option}" } # The main option as last entry before description option_def = .concat() << "--#{name}" << summary option_def.concat [{ default: default }] unless default.nil? .send type, *option_def . = nil rescue NoMethodError => e raise UltraCommandLine::Error, "Invalid option type '#{e.name}' for option '#{name}' !" end |