Class: Rootage::Command
Overview
Command is a scenario that has subcommands, options and arguments.
Direct Known Subclasses
Class Attribute Summary collapse
-
.argument_definition ⇒ Object
Returns the value of attribute argument_definition.
-
.option_definition ⇒ Object
Returns the value of attribute option_definition.
-
.subcommand ⇒ Object
Returns the value of attribute subcommand.
Instance Attribute Summary collapse
-
#argument_definition ⇒ Object
readonly
Returns the value of attribute argument_definition.
-
#argv ⇒ Object
readonly
Returns the value of attribute argv.
-
#option_definition ⇒ Object
readonly
Returns the value of attribute option_definition.
Attributes inherited from Scenario
#args, #current_phase, #exit_status, #info, #model, #running_thread
Class Method Summary collapse
-
.define_subcommand(name, subcommand) ⇒ Object
Define a subcommand.
-
.has_subcommands? ⇒ Boolean
Return true if the command has subcommands.
- .inherited(subclass) ⇒ Object
-
.init(action, &b) ⇒ Object
Define an action to phase "init".
-
.toplevel? ⇒ Boolean
Return true if the command is on toplevel.
Instance Method Summary collapse
- #<<(object) ⇒ Object
-
#exit ⇒ Object
Exit running command and return the status.
-
#initialize(*args) ⇒ Command
constructor
A new instance of Command.
- #program_name ⇒ Object
-
#run ⇒ void
Run a lifecycle of the command.
- #scenario_name ⇒ Object (also: #name)
Methods inherited from Scenario
#abort, define_action, make, require, run, scenario_name
Methods included from ScenarioInterface
#define, #define_phase, #desc, #phase, #phase_class, #process_context_class
Constructor Details
#initialize(*args) ⇒ Command
Returns a new instance of Command.
101 102 103 104 105 106 107 |
# File 'lib/rootage/command.rb', line 101 def initialize(*args) super @argv = args[0].clone @parent_name = args[1] @argument_definition = self.class.argument_definition.copy @option_definition = self.class.option_definition.copy end |
Class Attribute Details
.argument_definition ⇒ Object
Returns the value of attribute argument_definition.
32 33 34 |
# File 'lib/rootage/command.rb', line 32 def argument_definition @argument_definition end |
.option_definition ⇒ Object
Returns the value of attribute option_definition.
33 34 35 |
# File 'lib/rootage/command.rb', line 33 def option_definition @option_definition end |
.subcommand ⇒ Object
Returns the value of attribute subcommand.
31 32 33 |
# File 'lib/rootage/command.rb', line 31 def subcommand @subcommand end |
Instance Attribute Details
#argument_definition ⇒ Object (readonly)
Returns the value of attribute argument_definition.
99 100 101 |
# File 'lib/rootage/command.rb', line 99 def argument_definition @argument_definition end |
#argv ⇒ Object (readonly)
Returns the value of attribute argv.
97 98 99 |
# File 'lib/rootage/command.rb', line 97 def argv @argv end |
#option_definition ⇒ Object (readonly)
Returns the value of attribute option_definition.
98 99 100 |
# File 'lib/rootage/command.rb', line 98 def option_definition @option_definition end |
Class Method Details
.define_subcommand(name, subcommand) ⇒ Object
Define a subcommand.
74 75 76 |
# File 'lib/rootage/command.rb', line 74 def define_subcommand(name, subcommand) @subcommand[name] = subcommand end |
.has_subcommands? ⇒ Boolean
Return true if the command has subcommands.
82 83 84 |
# File 'lib/rootage/command.rb', line 82 def has_subcommands? not(@subcommand.values.compact.empty?) end |
.inherited(subclass) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/rootage/command.rb', line 35 def inherited(subclass) super subclass.subcommand = @subcommand.clone subclass.argument_definition = @argument_definition.copy subclass.option_definition = @option_definition.copy end |
.init(action, &b) ⇒ Object
Define an action to phase "init".
56 57 58 |
# File 'lib/rootage/command.rb', line 56 def init(action, &b) define_action(:init, action, &b) end |
.toplevel? ⇒ Boolean
Return true if the command is on toplevel.
64 65 66 |
# File 'lib/rootage/command.rb', line 64 def toplevel? @info.has_key?(:toplevel) ? @info[:toplevel] : false end |
Instance Method Details
#<<(object) ⇒ Object
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/rootage/command.rb', line 118 def <<(object) case object when Argument argument_definition << object when Option option_definition << object else super end end |
#exit ⇒ Object
Exit running command and return the status.
142 143 144 145 |
# File 'lib/rootage/command.rb', line 142 def exit super Kernel.exit(exit_status) end |
#program_name ⇒ Object
147 148 149 |
# File 'lib/rootage/command.rb', line 147 def program_name scenario_name end |
#run ⇒ void
This method returns an undefined value.
Run a lifecycle of the command.
132 133 134 135 136 137 138 139 |
# File 'lib/rootage/command.rb', line 132 def run load_requirements if has_subcommands? execute_subcommand end execute_phases exit end |
#scenario_name ⇒ Object Also known as: name
109 110 111 112 113 114 115 |
# File 'lib/rootage/command.rb', line 109 def scenario_name if @parent_name "%s %s" % [@parent_name, super] else super end end |