thor 0.19.1 → 0.19.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -0
- data/CONTRIBUTING.md +15 -0
- data/README.md +7 -1
- data/lib/thor.rb +31 -23
- data/lib/thor/actions.rb +21 -22
- data/lib/thor/actions/create_file.rb +1 -1
- data/lib/thor/actions/create_link.rb +1 -1
- data/lib/thor/actions/directory.rb +2 -2
- data/lib/thor/actions/empty_directory.rb +8 -8
- data/lib/thor/actions/file_manipulation.rb +23 -12
- data/lib/thor/actions/inject_into_file.rb +10 -14
- data/lib/thor/base.rb +33 -33
- data/lib/thor/command.rb +9 -9
- data/lib/thor/core_ext/hash_with_indifferent_access.rb +9 -1
- data/lib/thor/core_ext/io_binary_read.rb +7 -5
- data/lib/thor/core_ext/ordered_hash.rb +94 -63
- data/lib/thor/error.rb +3 -3
- data/lib/thor/group.rb +12 -12
- data/lib/thor/invocation.rb +4 -5
- data/lib/thor/parser/argument.rb +4 -7
- data/lib/thor/parser/arguments.rb +16 -16
- data/lib/thor/parser/option.rb +39 -19
- data/lib/thor/parser/options.rb +7 -5
- data/lib/thor/runner.rb +25 -25
- data/lib/thor/shell.rb +1 -1
- data/lib/thor/shell/basic.rb +41 -26
- data/lib/thor/shell/color.rb +1 -1
- data/lib/thor/shell/html.rb +4 -4
- data/lib/thor/util.rb +8 -7
- data/lib/thor/version.rb +1 -1
- data/thor.gemspec +6 -9
- metadata +6 -148
- data/Thorfile +0 -29
- data/spec/actions/create_file_spec.rb +0 -168
- data/spec/actions/create_link_spec.rb +0 -96
- data/spec/actions/directory_spec.rb +0 -169
- data/spec/actions/empty_directory_spec.rb +0 -129
- data/spec/actions/file_manipulation_spec.rb +0 -392
- data/spec/actions/inject_into_file_spec.rb +0 -135
- data/spec/actions_spec.rb +0 -331
- data/spec/base_spec.rb +0 -298
- data/spec/command_spec.rb +0 -79
- data/spec/core_ext/hash_with_indifferent_access_spec.rb +0 -48
- data/spec/core_ext/ordered_hash_spec.rb +0 -115
- data/spec/exit_condition_spec.rb +0 -19
- data/spec/fixtures/application.rb +0 -2
- data/spec/fixtures/app{1}/README +0 -3
- data/spec/fixtures/bundle/execute.rb +0 -6
- data/spec/fixtures/bundle/main.thor +0 -1
- data/spec/fixtures/command.thor +0 -10
- data/spec/fixtures/doc/%file_name%.rb.tt +0 -1
- data/spec/fixtures/doc/COMMENTER +0 -11
- data/spec/fixtures/doc/README +0 -3
- data/spec/fixtures/doc/block_helper.rb +0 -3
- data/spec/fixtures/doc/config.rb +0 -1
- data/spec/fixtures/doc/config.yaml.tt +0 -1
- data/spec/fixtures/doc/excluding/%file_name%.rb.tt +0 -1
- data/spec/fixtures/enum.thor +0 -10
- data/spec/fixtures/group.thor +0 -128
- data/spec/fixtures/invoke.thor +0 -131
- data/spec/fixtures/path with spaces b/data/spec/fixtures/path with → spaces +0 -0
- data/spec/fixtures/preserve/script.sh +0 -3
- data/spec/fixtures/script.thor +0 -220
- data/spec/fixtures/subcommand.thor +0 -17
- data/spec/group_spec.rb +0 -222
- data/spec/helper.rb +0 -80
- data/spec/invocation_spec.rb +0 -120
- data/spec/line_editor/basic_spec.rb +0 -28
- data/spec/line_editor/readline_spec.rb +0 -69
- data/spec/line_editor_spec.rb +0 -43
- data/spec/parser/argument_spec.rb +0 -53
- data/spec/parser/arguments_spec.rb +0 -66
- data/spec/parser/option_spec.rb +0 -210
- data/spec/parser/options_spec.rb +0 -414
- data/spec/quality_spec.rb +0 -75
- data/spec/rake_compat_spec.rb +0 -72
- data/spec/register_spec.rb +0 -227
- data/spec/runner_spec.rb +0 -246
- data/spec/sandbox/application.rb +0 -2
- data/spec/sandbox/app{1}/README +0 -3
- data/spec/sandbox/bundle/execute.rb +0 -6
- data/spec/sandbox/bundle/main.thor +0 -1
- data/spec/sandbox/command.thor +0 -10
- data/spec/sandbox/doc/%file_name%.rb.tt +0 -1
- data/spec/sandbox/doc/COMMENTER +0 -11
- data/spec/sandbox/doc/README +0 -3
- data/spec/sandbox/doc/block_helper.rb +0 -3
- data/spec/sandbox/doc/config.rb +0 -1
- data/spec/sandbox/doc/config.yaml.tt +0 -1
- data/spec/sandbox/doc/excluding/%file_name%.rb.tt +0 -1
- data/spec/sandbox/enum.thor +0 -10
- data/spec/sandbox/group.thor +0 -128
- data/spec/sandbox/invoke.thor +0 -131
- data/spec/sandbox/path with spaces b/data/spec/sandbox/path with → spaces +0 -0
- data/spec/sandbox/preserve/script.sh +0 -3
- data/spec/sandbox/script.thor +0 -220
- data/spec/sandbox/subcommand.thor +0 -17
- data/spec/shell/basic_spec.rb +0 -337
- data/spec/shell/color_spec.rb +0 -119
- data/spec/shell/html_spec.rb +0 -31
- data/spec/shell_spec.rb +0 -47
- data/spec/subcommand_spec.rb +0 -48
- data/spec/thor_spec.rb +0 -505
- data/spec/util_spec.rb +0 -196
data/spec/sandbox/application.rb
DELETED
data/spec/sandbox/app{1}/README
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'execute')
|
data/spec/sandbox/command.thor
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
FOO = <%= "FOO" %>
|
data/spec/sandbox/doc/COMMENTER
DELETED
data/spec/sandbox/doc/README
DELETED
data/spec/sandbox/doc/config.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
class <%= @klass %>; end
|
@@ -1 +0,0 @@
|
|
1
|
-
--- Hi from yaml
|
@@ -1 +0,0 @@
|
|
1
|
-
BAR = <%= "BAR" %>
|
data/spec/sandbox/enum.thor
DELETED
data/spec/sandbox/group.thor
DELETED
@@ -1,128 +0,0 @@
|
|
1
|
-
class MyCounter < Thor::Group
|
2
|
-
include Thor::Actions
|
3
|
-
add_runtime_options!
|
4
|
-
|
5
|
-
def self.get_from_super
|
6
|
-
from_superclass(:get_from_super, 13)
|
7
|
-
end
|
8
|
-
|
9
|
-
source_root File.expand_path(File.dirname(__FILE__))
|
10
|
-
source_paths << File.expand_path("broken", File.dirname(__FILE__))
|
11
|
-
|
12
|
-
argument :first, :type => :numeric
|
13
|
-
argument :second, :type => :numeric, :default => 2
|
14
|
-
|
15
|
-
class_option :third, :type => :numeric, :desc => "The third argument", :default => 3,
|
16
|
-
:banner => "THREE", :aliases => "-t"
|
17
|
-
class_option :fourth, :type => :numeric, :desc => "The fourth argument"
|
18
|
-
class_option :simple, :type => :numeric, :aliases => 'z'
|
19
|
-
class_option :symbolic, :type => :numeric, :aliases => [:y, :r]
|
20
|
-
|
21
|
-
desc <<-FOO
|
22
|
-
Description:
|
23
|
-
This generator runs three commands: one, two and three.
|
24
|
-
FOO
|
25
|
-
|
26
|
-
def one
|
27
|
-
first
|
28
|
-
end
|
29
|
-
|
30
|
-
def two
|
31
|
-
second
|
32
|
-
end
|
33
|
-
|
34
|
-
def three
|
35
|
-
options[:third]
|
36
|
-
end
|
37
|
-
|
38
|
-
def four
|
39
|
-
options[:fourth]
|
40
|
-
end
|
41
|
-
|
42
|
-
def five
|
43
|
-
options[:simple]
|
44
|
-
end
|
45
|
-
|
46
|
-
def six
|
47
|
-
options[:symbolic]
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.inherited(base)
|
51
|
-
super
|
52
|
-
base.source_paths.unshift(File.expand_path(File.join(File.dirname(__FILE__), "doc")))
|
53
|
-
end
|
54
|
-
|
55
|
-
no_commands do
|
56
|
-
def world(&block)
|
57
|
-
result = capture(&block)
|
58
|
-
concat(result.strip + " world!")
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
class ClearCounter < MyCounter
|
64
|
-
remove_argument :first, :second, :undefine => true
|
65
|
-
remove_class_option :third
|
66
|
-
|
67
|
-
def self.source_root
|
68
|
-
File.expand_path(File.join(File.dirname(__FILE__), "bundle"))
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
class BrokenCounter < MyCounter
|
73
|
-
namespace "app:broken:counter"
|
74
|
-
class_option :fail, :type => :boolean, :default => false
|
75
|
-
|
76
|
-
class << self
|
77
|
-
undef_method :source_root
|
78
|
-
end
|
79
|
-
|
80
|
-
def one
|
81
|
-
options[:first]
|
82
|
-
end
|
83
|
-
|
84
|
-
def four
|
85
|
-
respond_to?(:fail)
|
86
|
-
end
|
87
|
-
|
88
|
-
def five
|
89
|
-
options[:fail] ? this_method_does_not_exist : 5
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
class WhinyGenerator < Thor::Group
|
94
|
-
include Thor::Actions
|
95
|
-
|
96
|
-
def self.source_root
|
97
|
-
File.expand_path(File.dirname(__FILE__))
|
98
|
-
end
|
99
|
-
|
100
|
-
def wrong_arity(required)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
class CommandConflict < Thor::Group
|
105
|
-
desc "A group with the same name as a default command"
|
106
|
-
def group
|
107
|
-
puts "group"
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
class ParentGroup < Thor::Group
|
112
|
-
private
|
113
|
-
def foo
|
114
|
-
"foo"
|
115
|
-
end
|
116
|
-
|
117
|
-
def baz(name = 'baz')
|
118
|
-
name
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
class ChildGroup < ParentGroup
|
123
|
-
def bar
|
124
|
-
"bar"
|
125
|
-
end
|
126
|
-
|
127
|
-
public_command :foo, :baz
|
128
|
-
end
|
data/spec/sandbox/invoke.thor
DELETED
@@ -1,131 +0,0 @@
|
|
1
|
-
class A < Thor
|
2
|
-
include Thor::Actions
|
3
|
-
|
4
|
-
desc "one", "invoke one"
|
5
|
-
def one
|
6
|
-
p 1
|
7
|
-
invoke :two
|
8
|
-
invoke :three
|
9
|
-
end
|
10
|
-
|
11
|
-
desc "two", "invoke two"
|
12
|
-
def two
|
13
|
-
p 2
|
14
|
-
invoke :three
|
15
|
-
end
|
16
|
-
|
17
|
-
desc "three", "invoke three"
|
18
|
-
def three
|
19
|
-
p 3
|
20
|
-
end
|
21
|
-
|
22
|
-
desc "four", "invoke four"
|
23
|
-
def four
|
24
|
-
p 4
|
25
|
-
invoke "defined:five"
|
26
|
-
end
|
27
|
-
|
28
|
-
desc "five N", "check if number is equal 5"
|
29
|
-
def five(number)
|
30
|
-
number == 5
|
31
|
-
end
|
32
|
-
|
33
|
-
desc "invoker", "invoke a b command"
|
34
|
-
def invoker(*args)
|
35
|
-
invoke :b, :one, ["Jose"]
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
class B < Thor
|
40
|
-
class_option :last_name, :type => :string
|
41
|
-
|
42
|
-
desc "one FIRST_NAME", "invoke one"
|
43
|
-
def one(first_name)
|
44
|
-
"#{options.last_name}, #{first_name}"
|
45
|
-
end
|
46
|
-
|
47
|
-
desc "two", "invoke two"
|
48
|
-
def two
|
49
|
-
options
|
50
|
-
end
|
51
|
-
|
52
|
-
desc "three", "invoke three"
|
53
|
-
def three
|
54
|
-
self
|
55
|
-
end
|
56
|
-
|
57
|
-
desc "four", "invoke four"
|
58
|
-
option :defaulted_value, :type => :string, :default => 'default'
|
59
|
-
def four
|
60
|
-
options.defaulted_value
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
class C < Thor::Group
|
65
|
-
include Thor::Actions
|
66
|
-
|
67
|
-
def one
|
68
|
-
p 1
|
69
|
-
end
|
70
|
-
|
71
|
-
def two
|
72
|
-
p 2
|
73
|
-
end
|
74
|
-
|
75
|
-
def three
|
76
|
-
p 3
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
class Defined < Thor::Group
|
81
|
-
class_option :unused, :type => :boolean, :desc => "This option has no use"
|
82
|
-
|
83
|
-
def one
|
84
|
-
p 1
|
85
|
-
invoke "a:two"
|
86
|
-
invoke "a:three"
|
87
|
-
invoke "a:four"
|
88
|
-
invoke "defined:five"
|
89
|
-
end
|
90
|
-
|
91
|
-
def five
|
92
|
-
p 5
|
93
|
-
end
|
94
|
-
|
95
|
-
def print_status
|
96
|
-
say_status :finished, :counting
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
class E < Thor::Group
|
101
|
-
invoke Defined
|
102
|
-
end
|
103
|
-
|
104
|
-
class F < Thor::Group
|
105
|
-
invoke "b:one" do |instance, klass, command|
|
106
|
-
instance.invoke klass, command, [ "Jose" ], :last_name => "Valim"
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
class G < Thor::Group
|
111
|
-
class_option :invoked, :type => :string, :default => "defined"
|
112
|
-
invoke_from_option :invoked
|
113
|
-
end
|
114
|
-
|
115
|
-
class H < Thor::Group
|
116
|
-
class_option :defined, :type => :boolean, :default => true
|
117
|
-
invoke_from_option :defined
|
118
|
-
end
|
119
|
-
|
120
|
-
class I < Thor
|
121
|
-
desc "two", "Two"
|
122
|
-
def two
|
123
|
-
current_command_chain
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
class J < Thor
|
128
|
-
desc "i", "I"
|
129
|
-
subcommand :one, I
|
130
|
-
end
|
131
|
-
|
File without changes
|
data/spec/sandbox/script.thor
DELETED
@@ -1,220 +0,0 @@
|
|
1
|
-
class MyScript < Thor
|
2
|
-
check_unknown_options! :except => :with_optional
|
3
|
-
|
4
|
-
attr_accessor :some_attribute
|
5
|
-
attr_writer :another_attribute
|
6
|
-
attr_reader :another_attribute
|
7
|
-
|
8
|
-
private
|
9
|
-
attr_reader :private_attribute
|
10
|
-
|
11
|
-
public
|
12
|
-
group :script
|
13
|
-
default_command :example_default_command
|
14
|
-
|
15
|
-
map "-T" => :animal, ["-f", "--foo"] => :foo
|
16
|
-
|
17
|
-
map "animal_prison" => "zoo"
|
18
|
-
|
19
|
-
desc "zoo", "zoo around"
|
20
|
-
def zoo
|
21
|
-
true
|
22
|
-
end
|
23
|
-
|
24
|
-
desc "animal TYPE", "horse around"
|
25
|
-
|
26
|
-
no_commands do
|
27
|
-
def this_is_not_a_command
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def animal(type)
|
32
|
-
[type]
|
33
|
-
end
|
34
|
-
|
35
|
-
map "hid" => "hidden"
|
36
|
-
|
37
|
-
desc "hidden TYPE", "this is hidden", :hide => true
|
38
|
-
def hidden(type)
|
39
|
-
[type]
|
40
|
-
end
|
41
|
-
|
42
|
-
map "fu" => "zoo"
|
43
|
-
|
44
|
-
desc "foo BAR", <<END
|
45
|
-
do some fooing
|
46
|
-
This is more info!
|
47
|
-
Everyone likes more info!
|
48
|
-
END
|
49
|
-
method_option :force, :type => :boolean, :desc => "Force to do some fooing"
|
50
|
-
def foo(bar)
|
51
|
-
[bar, options]
|
52
|
-
end
|
53
|
-
|
54
|
-
desc "example_default_command", "example!"
|
55
|
-
method_options :with => :string
|
56
|
-
def example_default_command
|
57
|
-
options.empty? ? "default command" : options
|
58
|
-
end
|
59
|
-
|
60
|
-
desc "call_myself_with_wrong_arity", "get the right error"
|
61
|
-
def call_myself_with_wrong_arity
|
62
|
-
call_myself_with_wrong_arity(4)
|
63
|
-
end
|
64
|
-
|
65
|
-
desc "call_unexistent_method", "Call unexistent method inside a command"
|
66
|
-
def call_unexistent_method
|
67
|
-
boom!
|
68
|
-
end
|
69
|
-
|
70
|
-
desc "long_description", "a" * 80
|
71
|
-
long_desc <<-D
|
72
|
-
This is a really really really long description.
|
73
|
-
Here you go. So very long.
|
74
|
-
|
75
|
-
It even has two paragraphs.
|
76
|
-
D
|
77
|
-
def long_description
|
78
|
-
end
|
79
|
-
|
80
|
-
desc "name-with-dashes", "Ensure normalization of command names"
|
81
|
-
def name_with_dashes
|
82
|
-
end
|
83
|
-
|
84
|
-
method_options :all => :boolean
|
85
|
-
method_option :lazy, :lazy_default => "yes"
|
86
|
-
method_option :lazy_numeric, :type => :numeric, :lazy_default => 42
|
87
|
-
method_option :lazy_array, :type => :array, :lazy_default => %w[eat at joes]
|
88
|
-
method_option :lazy_hash, :type => :hash, :lazy_default => {'swedish' => 'meatballs'}
|
89
|
-
desc "with_optional NAME", "invoke with optional name"
|
90
|
-
def with_optional(name=nil, *args)
|
91
|
-
[name, options, args]
|
92
|
-
end
|
93
|
-
|
94
|
-
class AnotherScript < Thor
|
95
|
-
desc "baz", "do some bazing"
|
96
|
-
def baz
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
desc "send", "send as a command name"
|
101
|
-
def send
|
102
|
-
true
|
103
|
-
end
|
104
|
-
|
105
|
-
private
|
106
|
-
|
107
|
-
def method_missing(meth, *args)
|
108
|
-
if meth == :boom!
|
109
|
-
super
|
110
|
-
else
|
111
|
-
[meth, args]
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
desc "what", "what"
|
116
|
-
def what
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
class MyChildScript < MyScript
|
121
|
-
remove_command :bar
|
122
|
-
|
123
|
-
method_options :force => :boolean, :param => :numeric
|
124
|
-
def initialize(*args)
|
125
|
-
super
|
126
|
-
end
|
127
|
-
|
128
|
-
desc "zoo", "zoo around"
|
129
|
-
method_options :param => :required
|
130
|
-
def zoo
|
131
|
-
options
|
132
|
-
end
|
133
|
-
|
134
|
-
desc "animal TYPE", "horse around"
|
135
|
-
def animal(type)
|
136
|
-
[type, options]
|
137
|
-
end
|
138
|
-
method_option :other, :type => :string, :default => "method default", :for => :animal
|
139
|
-
desc "animal KIND", "fish around", :for => :animal
|
140
|
-
|
141
|
-
desc "boom", "explodes everything"
|
142
|
-
def boom
|
143
|
-
end
|
144
|
-
|
145
|
-
remove_command :boom, :undefine => true
|
146
|
-
end
|
147
|
-
|
148
|
-
class Barn < Thor
|
149
|
-
desc "open [ITEM]", "open the barn door"
|
150
|
-
def open(item = nil)
|
151
|
-
if item == "shotgun"
|
152
|
-
puts "That's going to leave a mark."
|
153
|
-
else
|
154
|
-
puts "Open sesame!"
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
desc "paint [COLOR]", "paint the barn"
|
159
|
-
method_option :coats, :type => :numeric, :default => 2, :desc => 'how many coats of paint'
|
160
|
-
def paint(color='red')
|
161
|
-
puts "#{options[:coats]} coats of #{color} paint"
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
class PackageNameScript < Thor
|
166
|
-
package_name "Baboon"
|
167
|
-
end
|
168
|
-
|
169
|
-
module Scripts
|
170
|
-
class MyScript < MyChildScript
|
171
|
-
argument :accessor, :type => :string
|
172
|
-
class_options :force => :boolean
|
173
|
-
method_option :new_option, :type => :string, :for => :example_default_command
|
174
|
-
|
175
|
-
def zoo
|
176
|
-
self.accessor
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
class MyDefaults < Thor
|
181
|
-
check_unknown_options!
|
182
|
-
|
183
|
-
namespace :default
|
184
|
-
desc "cow", "prints 'moo'"
|
185
|
-
def cow
|
186
|
-
puts "moo"
|
187
|
-
end
|
188
|
-
|
189
|
-
desc "command_conflict", "only gets called when prepended with a colon"
|
190
|
-
def command_conflict
|
191
|
-
puts "command"
|
192
|
-
end
|
193
|
-
|
194
|
-
desc "barn", "commands to manage the barn"
|
195
|
-
subcommand "barn", Barn
|
196
|
-
end
|
197
|
-
|
198
|
-
class ChildDefault < Thor
|
199
|
-
namespace "default:child"
|
200
|
-
end
|
201
|
-
|
202
|
-
class Arities < Thor
|
203
|
-
desc "zero_args", "takes zero args"
|
204
|
-
def zero_args
|
205
|
-
end
|
206
|
-
|
207
|
-
desc "one_arg ARG", "takes one arg"
|
208
|
-
def one_arg(arg)
|
209
|
-
end
|
210
|
-
|
211
|
-
desc "two_args ARG1 ARG2", "takes two args"
|
212
|
-
def two_args(arg1, arg2)
|
213
|
-
end
|
214
|
-
|
215
|
-
desc "optional_arg [ARG]", "takes an optional arg"
|
216
|
-
def optional_arg(arg='default')
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|