Class: ArgParser::CommandInstance

Inherits:
Argument
  • Object
show all
Defined in:
lib/arg-parser/argument.rb

Overview

Represents a specific command value for a CommandArgument, along with any additional arguments specific to this command.

Instance Attribute Summary collapse

Attributes inherited from Argument

#default, #description, #key, #on_parse, #required, #short_key, #usage_break

Instance Method Summary collapse

Methods inherited from Argument

lookup, register, to_key

Constructor Details

#initialize(cmd_val, desc, cmd_arg, arg_scope, opts = {}) ⇒ CommandInstance

Returns a new instance of CommandInstance.



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/arg-parser/argument.rb', line 211

def initialize(cmd_val, desc, cmd_arg, arg_scope, opts = {})
    if cmd_arg.on_parse
        if cmd_inst_op = opts[:on_parse]
            # Command and command instance both defined on_parse handlers
            opts[:on_parse] = lambda do |val, arg, hsh|
                cmd_arg.on_parse(val, arg, hsh)
                cmd_inst_op.on_parse(val, arg, hsh)
            end
        else
            opts[:on_parse] = cmd_arg.on_parse
        end
    end
    super(cmd_arg.key, desc, opts)
    @command_value = cmd_val
    @command_arg = cmd_arg
    @argument_scope = arg_scope
end

Instance Attribute Details

#argument_scopeObject (readonly)

Return an ArgumentScope for any additional arguments this command takes



208
209
210
# File 'lib/arg-parser/argument.rb', line 208

def argument_scope
  @argument_scope
end

#command_argObject (readonly)

Return the CommandArgument to which this CommandInstance relates



206
207
208
# File 'lib/arg-parser/argument.rb', line 206

def command_arg
  @command_arg
end

#command_valueObject (readonly)

Returns the constant value that identifies this CommandInstance.

Returns:

  • the constant value that identifies this CommandInstance



204
205
206
# File 'lib/arg-parser/argument.rb', line 204

def command_value
  @command_value
end

Instance Method Details

#to_sObject



229
230
231
# File 'lib/arg-parser/argument.rb', line 229

def to_s
    @command_value
end

#to_useObject



233
234
235
# File 'lib/arg-parser/argument.rb', line 233

def to_use
    @command_value
end