Class Clamp::Command
In: lib/clamp/command.rb
Parent: Object

{Command} models a shell command. Each command invocation is a new object. Command options and parameters are represented as attributes (see {Command::Declaration}).

The main entry-point is {run}, which uses {parse} to populate attributes based on an array of command-line arguments, then calls {execute} (which you provide) to make it go.

Methods

Included Modules

Clamp::Option::Parsing Clamp::Parameter::Parsing Clamp::Subcommand::Parsing Clamp::Option::Declaration Clamp::Parameter::Declaration Clamp::Subcommand::Declaration Help

Attributes

context  [RW] 
invocation_path  [R]  @return [String] the path used to invoke this command
remaining_arguments  [R]  @return [Array<String>] unconsumed command-line arguments

Public Class methods

Create a command execution.

@param [String] invocation_path the path used to invoke the command @param [Hash] context additional data the command may need

Public Instance methods

Execute the command (assuming that all options/parameters have been set).

This method is designed to be overridden in sub-classes.

@return [String] usage documentation for this command

Parse command-line arguments.

@param [Array<String>] arguments command-line arguments @return [Array<String>] unconsumed arguments

Run the command, with the specified arguments.

This calls {parse} to process the command-line arguments, then delegates to {execute}.

@param [Array<String>] arguments command-line arguments

Abort with subcommand missing usage error

@ param [String] name subcommand_name

Protected Instance methods

[Validate]