Class: Slugforge::Command

Inherits:
Thor
  • Object
show all
Includes:
Helper, Thor::Actions
Defined in:
lib/slugforge/commands.rb

Direct Known Subclasses

BuildCommand, Cli, SubCommand

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helper

included

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=[], options=[], 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.options)
    @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, options, 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