Method: Clamp::Subcommand::Declaration#subcommand

Defined in:
lib/clamp/subcommand/declaration.rb

#subcommand(name, description, subcommand_class = self, &block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/clamp/subcommand/declaration.rb', line 13

def subcommand(name, description, subcommand_class = self, &block)
  unless has_subcommands?
    @subcommand_parameter = if @default_subcommand
      parameter "[SUBCOMMAND]", "subcommand", :attribute_name => :subcommand_name, :default => @default_subcommand
    else
      parameter "SUBCOMMAND", "subcommand", :attribute_name => :subcommand_name, :required => false
    end
    remove_method :default_subcommand_name
    parameter "[ARG] ...", "subcommand arguments", :attribute_name => :subcommand_arguments
  end
  if block
    # generate a anonymous sub-class
    subcommand_class = Class.new(subcommand_class, &block)
  end
  recognised_subcommands << Subcommand::Definition.new(name, description, subcommand_class)
end