Class: Commands::CommandOption
Direct Known Subclasses
ArgOption, ArgsOption, FlagOption, GlobalFlagOption, GlobalOption, InstanceCountOption, InstanceTypeOption, OptionWithArg, ParamOption
Instance Attribute Summary collapse
-
#arg ⇒ Object
Returns the value of attribute arg.
-
#commands ⇒ Object
Returns the value of attribute commands.
-
#description ⇒ Object
Returns the value of attribute description.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent_commands ⇒ Object
Returns the value of attribute parent_commands.
Instance Method Summary collapse
- #attach(commands) ⇒ Object
-
#initialize(name, description, arg, parent_commands, commands, field_symbol = nil, pattern = nil) ⇒ CommandOption
constructor
A new instance of CommandOption.
Constructor Details
#initialize(name, description, arg, parent_commands, commands, field_symbol = nil, pattern = nil) ⇒ CommandOption
Returns a new instance of CommandOption.
188 189 190 191 192 193 194 195 196 |
# File 'lib/commands.rb', line 188 def initialize(name, description, arg, parent_commands, commands, field_symbol=nil, pattern=nil) @name = name @description = description @arg = arg @parent_commands = parent_commands @commands = commands @field_symbol = field_symbol @pattern = pattern end |
Instance Attribute Details
#arg ⇒ Object
Returns the value of attribute arg.
186 187 188 |
# File 'lib/commands.rb', line 186 def arg @arg end |
#commands ⇒ Object
Returns the value of attribute commands.
186 187 188 |
# File 'lib/commands.rb', line 186 def commands @commands end |
#description ⇒ Object
Returns the value of attribute description.
186 187 188 |
# File 'lib/commands.rb', line 186 def description @description end |
#name ⇒ Object
Returns the value of attribute name.
186 187 188 |
# File 'lib/commands.rb', line 186 def name @name end |
#parent_commands ⇒ Object
Returns the value of attribute parent_commands.
186 187 188 |
# File 'lib/commands.rb', line 186 def parent_commands @parent_commands end |
Instance Method Details
#attach(commands) ⇒ Object
198 199 200 201 202 203 204 205 206 |
# File 'lib/commands.rb', line 198 def attach(commands) for command in commands.reverse do command_name = command.name.split(/\s+/).first if @parent_commands.include?(command_name) || @parent_commands.include?(command.class) then return command end end raise RuntimeError, "Expected argument #{name} to follow one of #{parent_commands.join(", ")}" end |