Class: ArgParser::CommandBlock

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

Overview

Used to define arguments specific to a CommandInstance

Instance Method Summary collapse

Constructor Details

#initialize(arg_scope, cmd_arg, &block) ⇒ CommandBlock

Returns a new instance of CommandBlock.



318
319
320
321
322
# File 'lib/arg-parser/definition.rb', line 318

def initialize(arg_scope, cmd_arg, &block)
    @parent = arg_scope
    @command_arg = cmd_arg
    self.instance_eval(&block)
end

Instance Method Details

#command(key, desc, opts = {}, &block) ⇒ Object



332
333
334
335
336
337
# File 'lib/arg-parser/definition.rb', line 332

def command(key, desc, opts = {}, &block)
    cmd_arg_scope = ArgumentScope.new("Arguments for #{key} command", @parent)
    cmd_arg_scope.instance_eval(&block) if block_given?
    cmd_inst = CommandInstance.new(key, desc, @command_arg, cmd_arg_scope, opts)
    @command_arg << cmd_inst
end

#define_args(&block) ⇒ Object



325
326
327
328
329
# File 'lib/arg-parser/definition.rb', line 325

def define_args(&block)
    pre_def_arg_scope = ArgumentScope.new("Predefined args for #{@command_arg}")
    pre_def_arg_scope.instance_eval(&block)
    @parent.predefined_args = pre_def_arg_scope
end