Class: Slugforge::Command
- Inherits:
-
Thor
- Object
- Thor
- Slugforge::Command
- Includes:
- Helper, Thor::Actions
- Defined in:
- lib/slugforge/commands.rb
Direct Known Subclasses
Class Method Summary collapse
-
.start(given_args = ARGV, config = {}) ⇒ Object
Parses the command and options from the given args, instantiate the class and invoke the command.
Instance Method Summary collapse
-
#initialize(args = [], options = [], config = {}) ⇒ Command
constructor
Parameters args<Array>:: An array of objects.
Methods included from Helper
Constructor Details
#initialize(args = [], options = [], config = {}) ⇒ Command
Parameters
- args<Array>
-
An array of objects. The objects are applied to their respective accessors declared with
argument
. - options<Hash>
-
Either an array of command-line options requiring parsing or a hash of pre-parsed options.
- config<Hash>
-
Configuration for this Thor class.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/slugforge/commands.rb', line 55 def initialize(args=[], =[], config={}) @command_start_time = Time.now() super # Configuration must be # - created after command line is parsed (so not in #start) # - inherited from parent commands if config[:invoked_via_subcommand] @config = config[:shell].base.config else @config = Configuration.new(self.) @config.activate_slugins end end |
Class Method Details
.start(given_args = ARGV, config = {}) ⇒ Object
Parses the command and options from the given args, instantiate the class and invoke the command. This method is used when the arguments must be parsed from an array. If you are inside Ruby and want to use a Thor class, you can simply initialize it:
script = MyScript.new(args, , config)
script.invoke(:command, first_arg, second_arg, third_arg)
37 38 39 40 41 42 43 |
# File 'lib/slugforge/commands.rb', line 37 def start(given_args=ARGV, config={}) # Loads enabled slugins. This must be done before the CLI is instantiated so that new commands # will be found. Activation of slugins must be delayed until the command line options are parsed # so that the full config will be available. Configuration.new super end |