Class: Thor

Inherits:
Object
  • Object
show all
Defined in:
lib/everyday_thor_util/common.rb,
lib/everyday_thor_util/thor-fix.rb,
lib/everyday_thor_util/thor-print-fix.rb

Defined Under Namespace

Modules: Shell

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.parent_classObject

Returns the value of attribute parent_class.



5
6
7
# File 'lib/everyday_thor_util/thor-fix.rb', line 5

def parent_class
  @parent_class
end

Class Method Details



14
15
16
# File 'lib/everyday_thor_util/thor-fix.rb', line 14

def banner(command, namespace = nil, subcommand = false)
  "#{basename2(subcommand)} #{command.formatted_usage(self, $thor_runner, subcommand)}"
end

.basename2(subcommand = false) ⇒ Object



7
8
9
10
11
12
# File 'lib/everyday_thor_util/thor-fix.rb', line 7

def basename2(subcommand = false)
  bn  = parent_class && parent_class.basename2
  bn2 = basename
  ns  = self.namespace.split(':').last
  bn ? (subcommand ? bn : "#{bn} #{ns}") : bn2
end

.define_non_command(method_name, &block) ⇒ Object



13
14
15
# File 'lib/everyday_thor_util/common.rb', line 13

def define_non_command(method_name, &block)
  no_commands { define_method(method_name, &block) }
end

.handle_argument_error(command, error, args, arity) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/everyday_thor_util/thor-fix.rb', line 25

def handle_argument_error(command, error, args, arity)
  msg = "ERROR: \"#{basename2} #{command.name.gsub(/_/, '-')}\" was called with "
  msg << 'no arguments' if args.empty?
  msg << 'arguments ' << args.inspect unless args.empty?
  msg << "\nUsage: #{banner(command).inspect}"
  fail InvocationError, msg
end

.old_subcommandObject



18
# File 'lib/everyday_thor_util/thor-fix.rb', line 18

alias :old_subcommand :subcommand

.subcommand(subcommand, subcommand_class) ⇒ Object



20
21
22
23
# File 'lib/everyday_thor_util/thor-fix.rb', line 20

def subcommand(subcommand, subcommand_class)
  subcommand_class.parent_class = self
  old_subcommand(subcommand, subcommand_class)
end