Class: CommandLine::Arguments::Definition
- Inherits:
-
Object
- Object
- CommandLine::Arguments::Definition
- Defined in:
- lib/cli/command_line_arguments.rb
Constant Summary collapse
- ENDLESS_PARAMETERS =
99999
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#parameters ⇒ Object
Returns the value of attribute parameters.
Instance Method Summary collapse
- #[](option_name) ⇒ Object
- #command(name) {|command_definition| ... } ⇒ Object
- #has_command?(command) ⇒ Boolean
-
#initialize(parent) ⇒ Definition
constructor
A new instance of Definition.
- #minimum_parameters=(count_specifier) ⇒ Object
- #option(name, options = {}) ⇒ Object
- #switch(name, switch_alias = nil) ⇒ Object
Constructor Details
#initialize(parent) ⇒ Definition
Returns a new instance of Definition.
97 98 99 100 101 102 |
# File 'lib/cli/command_line_arguments.rb', line 97 def initialize(parent) @parent = parent = {} @commands = {} @parameters = nil end |
Instance Attribute Details
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
95 96 97 |
# File 'lib/cli/command_line_arguments.rb', line 95 def commands @commands end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
95 96 97 |
# File 'lib/cli/command_line_arguments.rb', line 95 def end |
#parameters ⇒ Object
Returns the value of attribute parameters.
95 96 97 |
# File 'lib/cli/command_line_arguments.rb', line 95 def parameters @parameters end |
Instance Method Details
#[](option_name) ⇒ Object
104 105 106 107 108 109 110 111 |
# File 'lib/cli/command_line_arguments.rb', line 104 def [](option_name) option_symbol = CommandLine::Option.rewrite(option_name) if the_option = .detect { |(name, odef)| odef =~ option_symbol } the_option[1] else raise CommandLine::UnknownOption, option_name end end |
#command(name) {|command_definition| ... } ⇒ Object
132 133 134 135 136 |
# File 'lib/cli/command_line_arguments.rb', line 132 def command(name, &block) command_definition = Definition.new(self) yield(command_definition) if block_given? @commands[CommandLine::Option.rewrite(name)] = command_definition end |
#has_command?(command) ⇒ Boolean
138 139 140 |
# File 'lib/cli/command_line_arguments.rb', line 138 def has_command?(command) @commands[CommandLine::Option.rewrite(command)] end |
#minimum_parameters=(count_specifier) ⇒ Object
113 114 115 |
# File 'lib/cli/command_line_arguments.rb', line 113 def minimum_parameters=(count_specifier) @parameters = count_specifier..ENDLESS_PARAMETERS end |
#option(name, options = {}) ⇒ Object
123 124 125 126 |
# File 'lib/cli/command_line_arguments.rb', line 123 def option(name, = {}) clo = CommandLine::Option.new(name, ) [clo.name] = clo end |
#switch(name, switch_alias = nil) ⇒ Object
128 129 130 |
# File 'lib/cli/command_line_arguments.rb', line 128 def switch(name, switch_alias = nil) option(name, :alias => switch_alias, :parameters => 0) end |