thor 0.18.1 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +13 -7
- data/Thorfile +4 -5
- data/bin/thor +1 -1
- data/lib/thor.rb +78 -67
- data/lib/thor/actions.rb +57 -56
- data/lib/thor/actions/create_file.rb +33 -35
- data/lib/thor/actions/create_link.rb +2 -3
- data/lib/thor/actions/directory.rb +37 -38
- data/lib/thor/actions/empty_directory.rb +67 -69
- data/lib/thor/actions/file_manipulation.rb +17 -15
- data/lib/thor/actions/inject_into_file.rb +27 -29
- data/lib/thor/base.rb +193 -189
- data/lib/thor/command.rb +20 -23
- data/lib/thor/core_ext/hash_with_indifferent_access.rb +21 -24
- data/lib/thor/core_ext/io_binary_read.rb +2 -4
- data/lib/thor/core_ext/ordered_hash.rb +9 -11
- data/lib/thor/error.rb +5 -1
- data/lib/thor/group.rb +53 -54
- data/lib/thor/invocation.rb +44 -38
- data/lib/thor/line_editor.rb +17 -0
- data/lib/thor/line_editor/basic.rb +35 -0
- data/lib/thor/line_editor/readline.rb +88 -0
- data/lib/thor/parser.rb +4 -4
- data/lib/thor/parser/argument.rb +28 -29
- data/lib/thor/parser/arguments.rb +102 -98
- data/lib/thor/parser/option.rb +26 -22
- data/lib/thor/parser/options.rb +86 -86
- data/lib/thor/rake_compat.rb +9 -10
- data/lib/thor/runner.rb +141 -141
- data/lib/thor/shell.rb +27 -34
- data/lib/thor/shell/basic.rb +91 -63
- data/lib/thor/shell/color.rb +44 -43
- data/lib/thor/shell/html.rb +59 -60
- data/lib/thor/util.rb +24 -27
- data/lib/thor/version.rb +1 -1
- data/spec/actions/create_file_spec.rb +25 -27
- data/spec/actions/create_link_spec.rb +19 -18
- data/spec/actions/directory_spec.rb +31 -31
- data/spec/actions/empty_directory_spec.rb +18 -18
- data/spec/actions/file_manipulation_spec.rb +38 -28
- data/spec/actions/inject_into_file_spec.rb +13 -13
- data/spec/actions_spec.rb +43 -43
- data/spec/base_spec.rb +45 -38
- data/spec/command_spec.rb +13 -14
- data/spec/core_ext/hash_with_indifferent_access_spec.rb +19 -19
- data/spec/core_ext/ordered_hash_spec.rb +6 -6
- data/spec/exit_condition_spec.rb +4 -4
- data/spec/fixtures/invoke.thor +19 -0
- data/spec/fixtures/script.thor +1 -1
- data/spec/group_spec.rb +30 -24
- data/spec/helper.rb +28 -15
- data/spec/invocation_spec.rb +39 -19
- data/spec/line_editor/basic_spec.rb +28 -0
- data/spec/line_editor/readline_spec.rb +69 -0
- data/spec/line_editor_spec.rb +43 -0
- data/spec/parser/argument_spec.rb +12 -12
- data/spec/parser/arguments_spec.rb +11 -11
- data/spec/parser/option_spec.rb +33 -25
- data/spec/parser/options_spec.rb +66 -52
- data/spec/quality_spec.rb +75 -0
- data/spec/rake_compat_spec.rb +10 -10
- data/spec/register_spec.rb +60 -30
- data/spec/runner_spec.rb +67 -62
- data/spec/sandbox/application.rb +2 -0
- data/spec/sandbox/app{1}/README +3 -0
- data/spec/sandbox/bundle/execute.rb +6 -0
- data/spec/sandbox/bundle/main.thor +1 -0
- data/spec/sandbox/command.thor +10 -0
- data/spec/sandbox/doc/%file_name%.rb.tt +1 -0
- data/spec/sandbox/doc/COMMENTER +11 -0
- data/spec/sandbox/doc/README +3 -0
- data/spec/sandbox/doc/block_helper.rb +3 -0
- data/spec/sandbox/doc/config.rb +1 -0
- data/spec/sandbox/doc/config.yaml.tt +1 -0
- data/spec/sandbox/doc/excluding/%file_name%.rb.tt +1 -0
- data/spec/sandbox/enum.thor +10 -0
- data/spec/sandbox/group.thor +128 -0
- data/spec/sandbox/invoke.thor +131 -0
- data/spec/sandbox/path with spaces b/data/spec/sandbox/path with → spaces +0 -0
- data/spec/sandbox/preserve/script.sh +3 -0
- data/spec/sandbox/script.thor +220 -0
- data/spec/sandbox/subcommand.thor +17 -0
- data/spec/shell/basic_spec.rb +107 -86
- data/spec/shell/color_spec.rb +32 -8
- data/spec/shell/html_spec.rb +3 -4
- data/spec/shell_spec.rb +7 -7
- data/spec/subcommand_spec.rb +20 -2
- data/spec/thor_spec.rb +111 -97
- data/spec/util_spec.rb +30 -30
- data/thor.gemspec +14 -14
- metadata +69 -25
data/lib/thor/command.rb
CHANGED
@@ -2,7 +2,7 @@ class Thor
|
|
2
2
|
class Command < Struct.new(:name, :description, :long_description, :usage, :options)
|
3
3
|
FILE_REGEXP = /^#{Regexp.escape(File.dirname(__FILE__))}/
|
4
4
|
|
5
|
-
def initialize(name, description, long_description, usage, options=nil)
|
5
|
+
def initialize(name, description, long_description, usage, options = nil)
|
6
6
|
super(name.to_s, description, long_description, usage, options || {})
|
7
7
|
end
|
8
8
|
|
@@ -17,7 +17,7 @@ class Thor
|
|
17
17
|
|
18
18
|
# By default, a command invokes a method in the thor class. You can change this
|
19
19
|
# implementation to create custom commands.
|
20
|
-
def run(instance, args=[])
|
20
|
+
def run(instance, args = [])
|
21
21
|
arity = nil
|
22
22
|
|
23
23
|
if private_method?(instance)
|
@@ -31,11 +31,9 @@ class Thor
|
|
31
31
|
instance.class.handle_no_command_error(name)
|
32
32
|
end
|
33
33
|
rescue ArgumentError => e
|
34
|
-
handle_argument_error?(instance, e, caller) ?
|
35
|
-
instance.class.handle_argument_error(self, e, args, arity) : (raise e)
|
34
|
+
handle_argument_error?(instance, e, caller) ? instance.class.handle_argument_error(self, e, args, arity) : (raise e)
|
36
35
|
rescue NoMethodError => e
|
37
|
-
handle_no_method_error?(instance, e, caller) ?
|
38
|
-
instance.class.handle_no_command_error(name) : (raise e)
|
36
|
+
handle_no_method_error?(instance, e, caller) ? instance.class.handle_no_command_error(name) : (fail e)
|
39
37
|
end
|
40
38
|
|
41
39
|
# Returns the formatted usage by injecting given required arguments
|
@@ -43,7 +41,7 @@ class Thor
|
|
43
41
|
def formatted_usage(klass, namespace = true, subcommand = false)
|
44
42
|
if namespace
|
45
43
|
namespace = klass.namespace
|
46
|
-
formatted = "#{namespace.gsub(/^(default)/,'')}:"
|
44
|
+
formatted = "#{namespace.gsub(/^(default)/, '')}:"
|
47
45
|
end
|
48
46
|
formatted = "#{klass.namespace.split(':').last} " if subcommand
|
49
47
|
|
@@ -51,12 +49,12 @@ class Thor
|
|
51
49
|
|
52
50
|
# Add usage with required arguments
|
53
51
|
formatted << if klass && !klass.arguments.empty?
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
52
|
+
usage.to_s.gsub(/^#{name}/) do |match|
|
53
|
+
match << " " << klass.arguments.map { |a| a.usage }.compact.join(" ")
|
54
|
+
end
|
55
|
+
else
|
56
|
+
usage.to_s
|
57
|
+
end
|
60
58
|
|
61
59
|
# Add required options
|
62
60
|
formatted << " #{required_options}"
|
@@ -72,7 +70,7 @@ class Thor
|
|
72
70
|
end
|
73
71
|
|
74
72
|
def required_options
|
75
|
-
@required_options ||= options.map{ |_, o| o.usage if o.required? }.compact.sort.join(" ")
|
73
|
+
@required_options ||= options.map { |_, o| o.usage if o.required? }.compact.sort.join(" ")
|
76
74
|
end
|
77
75
|
|
78
76
|
# Given a target, checks if this class name is a public method.
|
@@ -90,12 +88,12 @@ class Thor
|
|
90
88
|
end
|
91
89
|
|
92
90
|
def sans_backtrace(backtrace, caller) #:nodoc:
|
93
|
-
saned
|
94
|
-
saned
|
91
|
+
saned = backtrace.reject { |frame| frame =~ FILE_REGEXP || (frame =~ /\.java:/ && RUBY_PLATFORM =~ /java/) || (frame =~ /^kernel\// && RUBY_ENGINE =~ /rbx/) }
|
92
|
+
saned - caller
|
95
93
|
end
|
96
94
|
|
97
95
|
def handle_argument_error?(instance, error, caller)
|
98
|
-
not_debugging?(instance) && error.message =~ /wrong number of arguments/ && begin
|
96
|
+
not_debugging?(instance) && (error.message =~ /wrong number of arguments/ || error.message =~ /given \d*, expected \d*/) && begin
|
99
97
|
saned = sans_backtrace(error.backtrace, caller)
|
100
98
|
# Ruby 1.9 always include the called method in the backtrace
|
101
99
|
saned.empty? || (saned.size == 1 && RUBY_VERSION >= "1.9")
|
@@ -107,7 +105,7 @@ class Thor
|
|
107
105
|
error.message =~ /^undefined method `#{name}' for #{Regexp.escape(instance.to_s)}$/
|
108
106
|
end
|
109
107
|
end
|
110
|
-
Task = Command
|
108
|
+
Task = Command # rubocop:disable ConstantName
|
111
109
|
|
112
110
|
# A command that is hidden in help messages but still invocable.
|
113
111
|
class HiddenCommand < Command
|
@@ -115,15 +113,15 @@ class Thor
|
|
115
113
|
true
|
116
114
|
end
|
117
115
|
end
|
118
|
-
HiddenTask = HiddenCommand
|
116
|
+
HiddenTask = HiddenCommand # rubocop:disable ConstantName
|
119
117
|
|
120
118
|
# A dynamic command that handles method missing scenarios.
|
121
119
|
class DynamicCommand < Command
|
122
|
-
def initialize(name, options=nil)
|
120
|
+
def initialize(name, options = nil)
|
123
121
|
super(name.to_s, "A dynamically-generated command", name.to_s, name.to_s, options)
|
124
122
|
end
|
125
123
|
|
126
|
-
def run(instance, args=[])
|
124
|
+
def run(instance, args = [])
|
127
125
|
if (instance.methods & [name.to_s, name.to_sym]).empty?
|
128
126
|
super
|
129
127
|
else
|
@@ -131,6 +129,5 @@ class Thor
|
|
131
129
|
end
|
132
130
|
end
|
133
131
|
end
|
134
|
-
DynamicTask = DynamicCommand
|
135
|
-
|
132
|
+
DynamicTask = DynamicCommand # rubocop:disable ConstantName
|
136
133
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
class Thor
|
2
2
|
module CoreExt #:nodoc:
|
3
|
-
|
4
3
|
# A hash with indifferent access and magic predicates.
|
5
4
|
#
|
6
5
|
# hash = Thor::CoreExt::HashWithIndifferentAccess.new 'foo' => 'bar', 'baz' => 'bee', 'force' => true
|
@@ -10,8 +9,7 @@ class Thor
|
|
10
9
|
# hash.foo? #=> true
|
11
10
|
#
|
12
11
|
class HashWithIndifferentAccess < ::Hash #:nodoc:
|
13
|
-
|
14
|
-
def initialize(hash={})
|
12
|
+
def initialize(hash = {})
|
15
13
|
super()
|
16
14
|
hash.each do |key, value|
|
17
15
|
self[convert_key(key)] = value
|
@@ -31,7 +29,7 @@ class Thor
|
|
31
29
|
end
|
32
30
|
|
33
31
|
def values_at(*indices)
|
34
|
-
indices.
|
32
|
+
indices.map { |key| self[convert_key(key)] }
|
35
33
|
end
|
36
34
|
|
37
35
|
def merge(other)
|
@@ -50,31 +48,30 @@ class Thor
|
|
50
48
|
Hash.new(default).merge!(self)
|
51
49
|
end
|
52
50
|
|
53
|
-
|
51
|
+
protected
|
54
52
|
|
55
|
-
|
56
|
-
|
57
|
-
|
53
|
+
def convert_key(key)
|
54
|
+
key.is_a?(Symbol) ? key.to_s : key
|
55
|
+
end
|
58
56
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
else
|
71
|
-
self[$1] == args.first
|
72
|
-
end
|
57
|
+
# Magic predicates. For instance:
|
58
|
+
#
|
59
|
+
# options.force? # => !!options['force']
|
60
|
+
# options.shebang # => "/usr/lib/local/ruby"
|
61
|
+
# options.test_framework?(:rspec) # => options[:test_framework] == :rspec
|
62
|
+
#
|
63
|
+
def method_missing(method, *args, &block)
|
64
|
+
method = method.to_s
|
65
|
+
if method =~ /^(\w+)\?$/
|
66
|
+
if args.empty?
|
67
|
+
!!self[$1]
|
73
68
|
else
|
74
|
-
self[
|
69
|
+
self[$1] == args.first
|
75
70
|
end
|
71
|
+
else
|
72
|
+
self[method]
|
76
73
|
end
|
77
|
-
|
74
|
+
end
|
78
75
|
end
|
79
76
|
end
|
80
77
|
end
|
@@ -1,12 +1,10 @@
|
|
1
1
|
class IO #:nodoc:
|
2
2
|
class << self
|
3
|
-
|
4
3
|
def binread(file, *args)
|
5
|
-
|
6
|
-
File.open(file,
|
4
|
+
fail ArgumentError, "wrong number of arguments (#{1 + args.size} for 1..3)" unless args.size < 3
|
5
|
+
File.open(file, "rb") do |f|
|
7
6
|
f.read(*args)
|
8
7
|
end
|
9
8
|
end unless method_defined? :binread
|
10
|
-
|
11
9
|
end
|
12
10
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
class Thor
|
2
2
|
module CoreExt #:nodoc:
|
3
|
-
|
4
|
-
if RUBY_VERSION >= '1.9'
|
3
|
+
if RUBY_VERSION >= "1.9"
|
5
4
|
class OrderedHash < ::Hash
|
6
5
|
end
|
7
6
|
else
|
@@ -24,12 +23,12 @@ class Thor
|
|
24
23
|
end
|
25
24
|
|
26
25
|
def []=(key, value)
|
27
|
-
if node = @hash[key]
|
26
|
+
if node = @hash[key] # rubocop:disable AssignmentInCondition
|
28
27
|
node.value = value
|
29
28
|
else
|
30
29
|
node = Node.new(key, value)
|
31
30
|
|
32
|
-
if @first.nil?
|
31
|
+
if !defined?(@first) || @first.nil?
|
33
32
|
@first = @last = node
|
34
33
|
else
|
35
34
|
node.prev = @last
|
@@ -43,7 +42,7 @@ class Thor
|
|
43
42
|
end
|
44
43
|
|
45
44
|
def delete(key)
|
46
|
-
if node = @hash[key]
|
45
|
+
if node = @hash[key] # rubocop:disable AssignmentInCondition
|
47
46
|
prev_node = node.prev
|
48
47
|
next_node = node.next
|
49
48
|
|
@@ -61,25 +60,25 @@ class Thor
|
|
61
60
|
end
|
62
61
|
|
63
62
|
def keys
|
64
|
-
|
63
|
+
map { |k, v| k }
|
65
64
|
end
|
66
65
|
|
67
66
|
def values
|
68
|
-
|
67
|
+
map { |k, v| v }
|
69
68
|
end
|
70
69
|
|
71
70
|
def each
|
72
|
-
return unless @first
|
71
|
+
return unless defined?(@first) && @first
|
73
72
|
yield [@first.key, @first.value]
|
74
73
|
node = @first
|
75
|
-
yield [node.key, node.value] while node = node.next
|
74
|
+
yield [node.key, node.value] while node = node.next # rubocop:disable AssignmentInCondition
|
76
75
|
self
|
77
76
|
end
|
78
77
|
|
79
78
|
def merge(other)
|
80
79
|
hash = self.class.new
|
81
80
|
|
82
|
-
|
81
|
+
each do |key, value|
|
83
82
|
hash[key] = value
|
84
83
|
end
|
85
84
|
|
@@ -95,6 +94,5 @@ class Thor
|
|
95
94
|
end
|
96
95
|
end
|
97
96
|
end
|
98
|
-
|
99
97
|
end
|
100
98
|
end
|
data/lib/thor/error.rb
CHANGED
@@ -11,7 +11,11 @@ class Thor
|
|
11
11
|
# Raised when a command was not found.
|
12
12
|
class UndefinedCommandError < Error
|
13
13
|
end
|
14
|
-
UndefinedTaskError = UndefinedCommandError
|
14
|
+
UndefinedTaskError = UndefinedCommandError # rubocop:disable ConstantName
|
15
|
+
|
16
|
+
class AmbiguousCommandError < Error
|
17
|
+
end
|
18
|
+
AmbiguousTaskError = AmbiguousCommandError # rubocop:disable ConstantName
|
15
19
|
|
16
20
|
# Raised when a command was found, but not invoked properly.
|
17
21
|
class InvocationError < Error
|
data/lib/thor/group.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
1
|
+
require "thor/base"
|
2
2
|
|
3
3
|
# Thor has a special class called Thor::Group. The main difference to Thor class
|
4
4
|
# is that it invokes all commands at once. It also include some methods that allows
|
5
5
|
# invocations to be done at the class method, which are not available to Thor
|
6
6
|
# commands.
|
7
|
-
class Thor::Group
|
7
|
+
class Thor::Group # rubocop:disable ClassLength
|
8
8
|
class << self
|
9
9
|
# The description for this Thor::Group. If none is provided, but a source root
|
10
10
|
# exists, tries to find the USAGE one folder above it, otherwise searches
|
@@ -13,12 +13,11 @@ class Thor::Group
|
|
13
13
|
# ==== Parameters
|
14
14
|
# description<String>:: The description for this Thor::Group.
|
15
15
|
#
|
16
|
-
def desc(description=nil)
|
17
|
-
|
18
|
-
|
19
|
-
@desc || from_superclass(:desc, nil)
|
16
|
+
def desc(description = nil)
|
17
|
+
if description
|
18
|
+
@desc = description
|
20
19
|
else
|
21
|
-
|
20
|
+
@desc ||= from_superclass(:desc, nil)
|
22
21
|
end
|
23
22
|
end
|
24
23
|
|
@@ -32,7 +31,7 @@ class Thor::Group
|
|
32
31
|
shell.say " #{banner}\n"
|
33
32
|
shell.say
|
34
33
|
class_options_help(shell)
|
35
|
-
shell.say
|
34
|
+
shell.say desc if desc
|
36
35
|
end
|
37
36
|
|
38
37
|
# Stores invocations for this class merging with superclass values.
|
@@ -54,7 +53,7 @@ class Thor::Group
|
|
54
53
|
# The namespace/class given will have its options showed on the help
|
55
54
|
# usage. Check invoke_from_option for more information.
|
56
55
|
#
|
57
|
-
def invoke(*names, &block)
|
56
|
+
def invoke(*names, &block) # rubocop:disable MethodLength
|
58
57
|
options = names.last.is_a?(Hash) ? names.pop : {}
|
59
58
|
verbose = options.fetch(:verbose, true)
|
60
59
|
|
@@ -63,7 +62,7 @@ class Thor::Group
|
|
63
62
|
invocation_blocks[name] = block if block_given?
|
64
63
|
|
65
64
|
class_eval <<-METHOD, __FILE__, __LINE__
|
66
|
-
def _invoke_#{name.to_s.gsub(/\W/,
|
65
|
+
def _invoke_#{name.to_s.gsub(/\W/, "_")}
|
67
66
|
klass, command = self.class.prepare_for_invocation(nil, #{name.inspect})
|
68
67
|
|
69
68
|
if klass
|
@@ -108,13 +107,13 @@ class Thor::Group
|
|
108
107
|
# invoked. The block receives two parameters, an instance of the current
|
109
108
|
# class and the klass to be invoked.
|
110
109
|
#
|
111
|
-
def invoke_from_option(*names, &block)
|
110
|
+
def invoke_from_option(*names, &block) # rubocop:disable MethodLength
|
112
111
|
options = names.last.is_a?(Hash) ? names.pop : {}
|
113
112
|
verbose = options.fetch(:verbose, :white)
|
114
113
|
|
115
114
|
names.each do |name|
|
116
115
|
unless class_options.key?(name)
|
117
|
-
|
116
|
+
fail ArgumentError, "You have to define the option #{name.inspect} " <<
|
118
117
|
"before setting invoke_from_option."
|
119
118
|
end
|
120
119
|
|
@@ -122,7 +121,7 @@ class Thor::Group
|
|
122
121
|
invocation_blocks[name] = block if block_given?
|
123
122
|
|
124
123
|
class_eval <<-METHOD, __FILE__, __LINE__
|
125
|
-
def _invoke_from_option_#{name.to_s.gsub(/\W/,
|
124
|
+
def _invoke_from_option_#{name.to_s.gsub(/\W/, "_")}
|
126
125
|
return unless options[#{name.inspect}]
|
127
126
|
|
128
127
|
value = options[#{name.inspect}]
|
@@ -159,7 +158,7 @@ class Thor::Group
|
|
159
158
|
# Overwrite class options help to allow invoked generators options to be
|
160
159
|
# shown recursively when invoking a generator.
|
161
160
|
#
|
162
|
-
def class_options_help(shell, groups={}) #:nodoc:
|
161
|
+
def class_options_help(shell, groups = {}) #:nodoc:
|
163
162
|
get_options_from_invocations(groups, class_options) do |klass|
|
164
163
|
klass.send(:get_options_from_invocations, groups, class_options)
|
165
164
|
end
|
@@ -170,7 +169,7 @@ class Thor::Group
|
|
170
169
|
# options are added to group_options hash. Options that already exists
|
171
170
|
# in base_options are not added twice.
|
172
171
|
#
|
173
|
-
def get_options_from_invocations(group_options, base_options) #:nodoc:
|
172
|
+
def get_options_from_invocations(group_options, base_options) #:nodoc: # rubocop:disable MethodLength
|
174
173
|
invocations.each do |name, from_option|
|
175
174
|
value = if from_option
|
176
175
|
option = class_options[name]
|
@@ -200,70 +199,70 @@ class Thor::Group
|
|
200
199
|
def printable_commands(*)
|
201
200
|
item = []
|
202
201
|
item << banner
|
203
|
-
item << (desc ? "# #{desc.gsub(/\s+/m,' ')}" : "")
|
202
|
+
item << (desc ? "# #{desc.gsub(/\s+/m, ' ')}" : "")
|
204
203
|
[item]
|
205
204
|
end
|
206
|
-
|
205
|
+
alias_method :printable_tasks, :printable_commands
|
207
206
|
|
208
207
|
def handle_argument_error(command, error, args, arity) #:nodoc:
|
209
208
|
msg = "#{basename} #{command.name} takes #{arity} argument"
|
210
209
|
msg << "s" if arity > 1
|
211
210
|
msg << ", but it should not."
|
212
|
-
|
211
|
+
fail error, msg
|
213
212
|
end
|
214
213
|
|
215
|
-
|
214
|
+
protected
|
216
215
|
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
216
|
+
# The method responsible for dispatching given the args.
|
217
|
+
def dispatch(command, given_args, given_opts, config) #:nodoc:
|
218
|
+
if Thor::HELP_MAPPINGS.include?(given_args.first)
|
219
|
+
help(config[:shell])
|
220
|
+
return
|
221
|
+
end
|
223
222
|
|
224
|
-
|
225
|
-
|
223
|
+
args, opts = Thor::Options.split(given_args)
|
224
|
+
opts = given_opts || opts
|
226
225
|
|
227
|
-
|
228
|
-
|
226
|
+
instance = new(args, opts, config)
|
227
|
+
yield instance if block_given?
|
229
228
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
end
|
229
|
+
if command
|
230
|
+
instance.invoke_command(all_commands[command])
|
231
|
+
else
|
232
|
+
instance.invoke_all
|
235
233
|
end
|
234
|
+
end
|
236
235
|
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
236
|
+
# The banner for this class. You can customize it if you are invoking the
|
237
|
+
# thor class by another ways which is not the Thor::Runner.
|
238
|
+
def banner
|
239
|
+
"#{basename} #{self_command.formatted_usage(self, false)}"
|
240
|
+
end
|
242
241
|
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
242
|
+
# Represents the whole class as a command.
|
243
|
+
def self_command #:nodoc:
|
244
|
+
Thor::DynamicCommand.new(namespace, class_options)
|
245
|
+
end
|
246
|
+
alias_method :self_task, :self_command
|
248
247
|
|
249
|
-
|
250
|
-
|
251
|
-
|
248
|
+
def baseclass #:nodoc:
|
249
|
+
Thor::Group
|
250
|
+
end
|
252
251
|
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
252
|
+
def create_command(meth) #:nodoc:
|
253
|
+
commands[meth.to_s] = Thor::Command.new(meth, nil, nil, nil, nil)
|
254
|
+
true
|
255
|
+
end
|
256
|
+
alias_method :create_task, :create_command
|
258
257
|
end
|
259
258
|
|
260
259
|
include Thor::Base
|
261
260
|
|
262
|
-
|
261
|
+
protected
|
263
262
|
|
264
263
|
# Shortcut to invoke with padding and block handling. Use internally by
|
265
264
|
# invoke and invoke_from_option class methods.
|
266
|
-
def _invoke_for_class_method(klass, command=nil, *args, &block) #:nodoc:
|
265
|
+
def _invoke_for_class_method(klass, command = nil, *args, &block) #:nodoc:
|
267
266
|
with_padding do
|
268
267
|
if block
|
269
268
|
case block.arity
|