Class Drydock::Command
In: lib/drydock.rb
Parent: Object

The base class for all command objects. There is an instance of this class for every command defined. Global and command-specific options are added as attributes to this class dynamically.

    i.e. "example -v select --location kumamoto"

    global :v, :verbose, "I want mooooore!"
    option :l, :location, String, "Source location"
    command :select do |obj|
      puts obj.global.verbose   #=> true
      puts obj.option.location  #=> "kumamoto"
    end

You can sub-class it to create your own:

    class Malpeque < Drydock::Command
      # ... sea to it
    end

And then specify your class in the command definition:

    command :eat => Malpeque do |obj|
      # ... do stuff with your obj
    end

Methods

call   name   new   prepare   show_commands   to_s  

Constants

VERSION = "0.6.9"

Attributes

actions  [RW]  An array of action names specified in the command definition
alias  [R]  The name used to evoke this command (it‘s either the canonical name or the alias used).
argv  [RW]  An instance of Drydock::FancyArray. Acts like an array of unnamed arguments but also allows field names if supplied.
b  [R]  The block that will be executed when this command is evoked. If the block is nil it will check if there is a method named cmd. If so, that will be executed.
cmd  [R]  The canonical name of the command (the one used in the command definition). If you inherit from this class and add a method named cmd, you can leave omit the block in the command definition. That method will be called instead. See bin/examples.
desc  [RW]  A friendly description of the command.
executable  [R]  The basename of the executable or script: File.basename($0)
global  [R]  An OpenStruct object containing the global options specified at run-time.
option  [R]  An OpenStruct object containing the command options specified at run-time.
stdin  [R]  Either an IO handle to STDIN or the output of the Drydock#stdin handler.

Public Class methods

The default constructor sets the short name of the command and stores a reference to the block (if supplied). You don‘t need to override this method to add functionality to your custom Command classes. Define an init method instead. It will be called just before the block is executed. cmd is the short name of this command. b is the block associated to this command.

Public Instance methods

Calls the command in the following order:

  • print_header
  • validation (if methodname_valid? exists)
  • command block (@b)
  • print_footer

Returns the command name (not the alias)

Prepare this command object to be called.

Calls self.init after setting attributes (if the method exists). You can implement an init method in your subclasses of Drydock::Command to handle your own initialization stuff.

<li>cmd_str is the short name used to evoke this command. It will equal @cmd unless an alias was used used to evoke this command.</li> <li>argv an array of unnamed arguments. If ignore :options was declared this</li> will contain the arguments exactly as they were defined on the command-line.</li> <li>stdin contains the output of stdin do; …; end otherwise it‘s a STDIN IO handle.</li> <li>global_options a hash of the global options specified on the command-line</li> <li>options a hash of the command-specific options specific on the command-line.</li>

Print the list of available commands to STDOUT. This is used as the "default" command unless another default commands is supplied. You can also write your own Drydock::Command#show_commands to override this default behaviour.

The output was worked on here: etherpad.com/SXjqQGRr8M

The name of the command

[Validate]