Method: CommandKit::Commands::ClassMethods#command

Defined in:
lib/command_kit/commands.rb

#command(name = nil, command_class, **kwargs) ⇒ Subcommand

Mounts a command as a sub-command.

Examples:

command Foo
command 'foo-bar', FooBar

Parameters:

  • name (#to_s) (defaults to: nil)

    The optional name to mount the command as. Defaults to the command's command_name.

  • command_class (Class#main)

    The sub-command class.

  • kwargs (Hash{Symbol => Object})

    Keyword arguments.

  • kwags (Hash)

    a customizable set of options

Options Hash (**kwargs):

  • summary (String, nil)

    A short summary for the subcommand. Defaults to the first sentence of the command.

Returns:

  • (Subcommand)

    The registered sub-command class.



144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/command_kit/commands.rb', line 144

def command(name=nil, command_class, **kwargs)
  name = if name then name.to_s
         else         command_class.command_name
         end

  subcommand = Subcommand.new(command_class,**kwargs)
  commands[name] = subcommand

  subcommand.aliases.each do |alias_name|
    command_aliases[alias_name] = name
  end

  return subcommand
end