class Slugforge::Command

Public Class Methods

new(args=[], options=[], config={}) click to toggle source

Parameters

args>

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.

Calls superclass method
# 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
start(given_args=ARGV, config={}) click to toggle source

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)
Calls superclass method
# 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

Protected Class Methods

exit_on_failure?() click to toggle source
# File lib/slugforge/commands.rb, line 77
def self.exit_on_failure?
  true
end
inherited(base) click to toggle source
# File lib/slugforge/commands.rb, line 81
def self.inherited(base)
  base.source_root templates_dir
end

Protected Instance Methods

config() click to toggle source
# File lib/slugforge/commands.rb, line 73
def config
  @config
end
publish(event, *args) click to toggle source
# File lib/slugforge/commands.rb, line 85
def publish(event, *args)
  ActiveSupport::Notifications.publish(event, self, *args) if notifications_enabled?
rescue => e
  clean_trace = e.backtrace.reject { |l| l =~ /active_support|thor|bin\/slugforge/ } # reject parts of the stack containing active_support, thor, or bin/slugforge
  logger.say_status :error, "[notification #{args.first}] #{e.message}\n" + clean_trace.join("\n"), :red
end