Class: Thor
- Inherits:
-
Object
- Object
- Thor
- 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
-
.parent_class ⇒ Object
Returns the value of attribute parent_class.
Class Method Summary collapse
- .banner(command, namespace = nil, subcommand = false) ⇒ Object
- .basename2(subcommand = false) ⇒ Object
- .define_non_command(method_name, &block) ⇒ Object
- .handle_argument_error(command, error, args, arity) ⇒ Object
- .old_subcommand ⇒ Object
- .subcommand(subcommand, subcommand_class) ⇒ Object
Class Attribute Details
.parent_class ⇒ Object
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
.banner(command, namespace = nil, subcommand = false) ⇒ Object
14 15 16 |
# File 'lib/everyday_thor_util/thor-fix.rb', line 14 def (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: #{(command).inspect}" fail InvocationError, msg end |
.old_subcommand ⇒ Object
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 |