Method: Command::DSL::CommandDefinition#parent_argument

Defined in:
lib/command-set/dsl.rb

#parent_argument(name) ⇒ Object

Creates a parent argument reference: an argument that references an argument from a subcommand. This lets a subcommand collect the arguments common to its commands and do two things: make command line calls more natural (+box+ grape_box add grapes instead of box add grape_box grapes) and also make modes more useful, since they can collect the arguments that would otherwise be repeated when the mode is started.

Raises:



378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
# File 'lib/command-set/dsl.rb', line 378

def parent_argument(name)
  name = name.to_s
  search_in = parent
  until (search_in = search_in.parent()).nil? do
    found = parent.argument_list.find do |argument|
      argument.names.include? name
    end
    unless found.nil?
      arg = found
      @parent_arguments << found
      return
    end
  end
  raise CommandError, "No parent has an argument named \"#{name}\""
end