acquia_toolbelt 2.3.0 → 2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/CONTRIBUTING.md +11 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +55 -0
- data/Guardfile +5 -0
- data/LICENSE +19 -0
- data/README.md +149 -0
- data/Rakefile +1 -0
- data/acquia_toolbelt.gemspec +34 -0
- data/bin/acquia +9 -0
- data/lib/acquia_toolbelt/cli/api.rb +164 -0
- data/lib/acquia_toolbelt/cli/auth.rb +31 -0
- data/lib/acquia_toolbelt/cli/database.rb +237 -0
- data/lib/acquia_toolbelt/cli/deploy.rb +36 -0
- data/lib/acquia_toolbelt/cli/domain.rb +177 -0
- data/lib/acquia_toolbelt/cli/environment.rb +71 -0
- data/lib/acquia_toolbelt/cli/file.rb +31 -0
- data/lib/acquia_toolbelt/cli/server.rb +67 -0
- data/lib/acquia_toolbelt/cli/site.rb +28 -0
- data/lib/acquia_toolbelt/cli/ssh.rb +78 -0
- data/lib/acquia_toolbelt/cli/svn.rb +73 -0
- data/lib/acquia_toolbelt/cli/task.rb +74 -0
- data/lib/acquia_toolbelt/cli/ui.rb +44 -0
- data/lib/acquia_toolbelt/cli.rb +103 -0
- data/lib/acquia_toolbelt/error.rb +4 -0
- data/lib/acquia_toolbelt/thor.rb +95 -0
- data/lib/acquia_toolbelt/version.rb +3 -0
- data/lib/acquia_toolbelt.rb +4 -0
- data/lib/vendor/thor/CHANGELOG.md +139 -0
- data/lib/vendor/thor/Gemfile +20 -0
- data/lib/vendor/thor/LICENSE.md +20 -0
- data/lib/vendor/thor/README.md +35 -0
- data/lib/vendor/thor/lib/thor/actions/create_file.rb +105 -0
- data/lib/vendor/thor/lib/thor/actions/create_link.rb +60 -0
- data/lib/vendor/thor/lib/thor/actions/directory.rb +119 -0
- data/lib/vendor/thor/lib/thor/actions/empty_directory.rb +137 -0
- data/lib/vendor/thor/lib/thor/actions/file_manipulation.rb +317 -0
- data/lib/vendor/thor/lib/thor/actions/inject_into_file.rb +109 -0
- data/lib/vendor/thor/lib/thor/actions.rb +318 -0
- data/lib/vendor/thor/lib/thor/base.rb +654 -0
- data/lib/vendor/thor/lib/thor/command.rb +136 -0
- data/lib/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +80 -0
- data/lib/vendor/thor/lib/thor/core_ext/io_binary_read.rb +12 -0
- data/lib/vendor/thor/lib/thor/core_ext/ordered_hash.rb +100 -0
- data/lib/vendor/thor/lib/thor/error.rb +32 -0
- data/lib/vendor/thor/lib/thor/group.rb +282 -0
- data/lib/vendor/thor/lib/thor/invocation.rb +172 -0
- data/lib/vendor/thor/lib/thor/parser/argument.rb +74 -0
- data/lib/vendor/thor/lib/thor/parser/arguments.rb +171 -0
- data/lib/vendor/thor/lib/thor/parser/option.rb +121 -0
- data/lib/vendor/thor/lib/thor/parser/options.rb +218 -0
- data/lib/vendor/thor/lib/thor/parser.rb +4 -0
- data/lib/vendor/thor/lib/thor/rake_compat.rb +72 -0
- data/lib/vendor/thor/lib/thor/runner.rb +322 -0
- data/lib/vendor/thor/lib/thor/shell/basic.rb +422 -0
- data/lib/vendor/thor/lib/thor/shell/color.rb +148 -0
- data/lib/vendor/thor/lib/thor/shell/html.rb +127 -0
- data/lib/vendor/thor/lib/thor/shell.rb +88 -0
- data/lib/vendor/thor/lib/thor/util.rb +270 -0
- data/lib/vendor/thor/lib/thor/version.rb +3 -0
- data/lib/vendor/thor/lib/thor.rb +474 -0
- data/lib/vendor/thor/spec/actions/create_file_spec.rb +170 -0
- data/lib/vendor/thor/spec/actions/create_link_spec.rb +95 -0
- data/lib/vendor/thor/spec/actions/directory_spec.rb +169 -0
- data/lib/vendor/thor/spec/actions/empty_directory_spec.rb +129 -0
- data/lib/vendor/thor/spec/actions/file_manipulation_spec.rb +382 -0
- data/lib/vendor/thor/spec/actions/inject_into_file_spec.rb +135 -0
- data/lib/vendor/thor/spec/actions_spec.rb +331 -0
- data/lib/vendor/thor/spec/base_spec.rb +291 -0
- data/lib/vendor/thor/spec/command_spec.rb +80 -0
- data/lib/vendor/thor/spec/core_ext/hash_with_indifferent_access_spec.rb +48 -0
- data/lib/vendor/thor/spec/core_ext/ordered_hash_spec.rb +115 -0
- data/lib/vendor/thor/spec/exit_condition_spec.rb +19 -0
- data/lib/vendor/thor/spec/fixtures/application.rb +2 -0
- data/lib/vendor/thor/spec/fixtures/app{1}/README +3 -0
- data/lib/vendor/thor/spec/fixtures/bundle/execute.rb +6 -0
- data/lib/vendor/thor/spec/fixtures/bundle/main.thor +1 -0
- data/lib/vendor/thor/spec/fixtures/command.thor +10 -0
- data/lib/vendor/thor/spec/fixtures/doc/%file_name%.rb.tt +1 -0
- data/lib/vendor/thor/spec/fixtures/doc/COMMENTER +11 -0
- data/lib/vendor/thor/spec/fixtures/doc/README +3 -0
- data/lib/vendor/thor/spec/fixtures/doc/block_helper.rb +3 -0
- data/lib/vendor/thor/spec/fixtures/doc/components/.empty_directory +0 -0
- data/lib/vendor/thor/spec/fixtures/doc/config.rb +1 -0
- data/lib/vendor/thor/spec/fixtures/doc/config.yaml.tt +1 -0
- data/lib/vendor/thor/spec/fixtures/doc/excluding/%file_name%.rb.tt +1 -0
- data/lib/vendor/thor/spec/fixtures/enum.thor +10 -0
- data/lib/vendor/thor/spec/fixtures/group.thor +128 -0
- data/lib/vendor/thor/spec/fixtures/invoke.thor +118 -0
- data/lib/vendor/thor/spec/fixtures/path with spaces +0 -0
- data/lib/vendor/thor/spec/fixtures/preserve/script.sh +3 -0
- data/lib/vendor/thor/spec/fixtures/script.thor +220 -0
- data/lib/vendor/thor/spec/fixtures/subcommand.thor +17 -0
- data/lib/vendor/thor/spec/group_spec.rb +222 -0
- data/lib/vendor/thor/spec/helper.rb +67 -0
- data/lib/vendor/thor/spec/invocation_spec.rb +108 -0
- data/lib/vendor/thor/spec/parser/argument_spec.rb +53 -0
- data/lib/vendor/thor/spec/parser/arguments_spec.rb +66 -0
- data/lib/vendor/thor/spec/parser/option_spec.rb +202 -0
- data/lib/vendor/thor/spec/parser/options_spec.rb +400 -0
- data/lib/vendor/thor/spec/rake_compat_spec.rb +72 -0
- data/lib/vendor/thor/spec/register_spec.rb +197 -0
- data/lib/vendor/thor/spec/runner_spec.rb +241 -0
- data/lib/vendor/thor/spec/shell/basic_spec.rb +330 -0
- data/lib/vendor/thor/spec/shell/color_spec.rb +95 -0
- data/lib/vendor/thor/spec/shell/html_spec.rb +31 -0
- data/lib/vendor/thor/spec/shell_spec.rb +47 -0
- data/lib/vendor/thor/spec/subcommand_spec.rb +30 -0
- data/lib/vendor/thor/spec/thor_spec.rb +499 -0
- data/lib/vendor/thor/spec/util_spec.rb +196 -0
- data/lib/vendor/thor/thor.gemspec +24 -0
- data/script/release +50 -0
- data/script/setup_build +6 -0
- data/script/test +23 -0
- data/spec/auth_spec.rb +15 -0
- data/spec/cassettes/databases/all_databases.json +1 -0
- data/spec/cassettes/databases/copy_database_from_dev_to_stage.json +1 -0
- data/spec/cassettes/databases/create_a_database_backup.json +1 -0
- data/spec/cassettes/databases/create_a_new_database.json +1 -0
- data/spec/cassettes/databases/delete_a_database.json +1 -0
- data/spec/cassettes/databases/get_all_existing_databases.json +1 -0
- data/spec/cassettes/databases/list_all_database_backups.json +1 -0
- data/spec/cassettes/databases/view_database_instance_details.json +1 -0
- data/spec/cassettes/deploy/release_vcs_branch.json +1 -0
- data/spec/cassettes/domains/create_new_domain.json +1 -0
- data/spec/cassettes/domains/delete_a_domain.json +1 -0
- data/spec/cassettes/domains/get_all_existing_domains.json +1 -0
- data/spec/cassettes/domains/list_all_dev_domains.json +1 -0
- data/spec/cassettes/domains/move_from_dev_to_stage.json +1 -0
- data/spec/cassettes/domains/purge_varnish_cache.json +1 -0
- data/spec/cassettes/environments/all_environments.json +1 -0
- data/spec/cassettes/environments/disable_live_development.json +1 -0
- data/spec/cassettes/environments/enable_live_development.json +1 -0
- data/spec/cassettes/files/copy_from_dev_to_stage.json +1 -0
- data/spec/cassettes/servers/all_dev_servers.json +1 -0
- data/spec/cassettes/servers/all_prod_servers.json +1 -0
- data/spec/cassettes/sites/all_sites.json +1 -0
- data/spec/cassettes/ssh/all_sshkeys.json +1 -0
- data/spec/cassettes/svn/all_svnusers.json +1 -0
- data/spec/cassettes/tasks/all_tasks.json +1 -0
- data/spec/databases_spec.rb +78 -0
- data/spec/deploy_spec.rb +12 -0
- data/spec/domains_spec.rb +59 -0
- data/spec/environments_spec.rb +35 -0
- data/spec/files_spec.rb +11 -0
- data/spec/helper.rb +104 -0
- data/spec/servers_spec.rb +59 -0
- data/spec/sites_spec.rb +19 -0
- data/spec/ssh_spec.rb +19 -0
- data/spec/svn_spec.rb +11 -0
- data/spec/tasks_spec.rb +11 -0
- metadata +158 -4
@@ -0,0 +1,499 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Thor do
|
4
|
+
describe "#method_option" do
|
5
|
+
it "sets options to the next method to be invoked" do
|
6
|
+
args = ["foo", "bar", "--force"]
|
7
|
+
arg, options = MyScript.start(args)
|
8
|
+
expect(options).to eq({ "force" => true })
|
9
|
+
end
|
10
|
+
|
11
|
+
describe ":lazy_default" do
|
12
|
+
it "is absent when option is not specified" do
|
13
|
+
arg, options = MyScript.start(["with_optional"])
|
14
|
+
expect(options).to eq({})
|
15
|
+
end
|
16
|
+
|
17
|
+
it "sets a default that can be overridden for strings" do
|
18
|
+
arg, options = MyScript.start(["with_optional", "--lazy"])
|
19
|
+
expect(options).to eq({ "lazy" => "yes" })
|
20
|
+
|
21
|
+
arg, options = MyScript.start(["with_optional", "--lazy", "yesyes!"])
|
22
|
+
expect(options).to eq({ "lazy" => "yesyes!" })
|
23
|
+
end
|
24
|
+
|
25
|
+
it "sets a default that can be overridden for numerics" do
|
26
|
+
arg, options = MyScript.start(["with_optional", "--lazy-numeric"])
|
27
|
+
expect(options).to eq({ "lazy_numeric" => 42 })
|
28
|
+
|
29
|
+
arg, options = MyScript.start(["with_optional", "--lazy-numeric", 20000])
|
30
|
+
expect(options).to eq({ "lazy_numeric" => 20000 })
|
31
|
+
end
|
32
|
+
|
33
|
+
it "sets a default that can be overridden for arrays" do
|
34
|
+
arg, options = MyScript.start(["with_optional", "--lazy-array"])
|
35
|
+
expect(options).to eq({ "lazy_array" => %w[eat at joes] })
|
36
|
+
|
37
|
+
arg, options = MyScript.start(["with_optional", "--lazy-array", "hello", "there"])
|
38
|
+
expect(options).to eq({ "lazy_array" => %w[hello there] })
|
39
|
+
end
|
40
|
+
|
41
|
+
it "sets a default that can be overridden for hashes" do
|
42
|
+
arg, options = MyScript.start(["with_optional", "--lazy-hash"])
|
43
|
+
expect(options).to eq({ "lazy_hash" => {'swedish' => 'meatballs'} })
|
44
|
+
|
45
|
+
arg, options = MyScript.start(["with_optional", "--lazy-hash", "polish:sausage"])
|
46
|
+
expect(options).to eq({ "lazy_hash" => {'polish' => 'sausage'} })
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "when :for is supplied" do
|
51
|
+
it "updates an already defined command" do
|
52
|
+
args, options = MyChildScript.start(["animal", "horse", "--other=fish"])
|
53
|
+
expect(options[:other]).to eq("fish")
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "and the target is on the parent class" do
|
57
|
+
it "updates an already defined command" do
|
58
|
+
args = ["example_default_command", "my_param", "--new-option=verified"]
|
59
|
+
options = Scripts::MyScript.start(args)
|
60
|
+
expect(options[:new_option]).to eq("verified")
|
61
|
+
end
|
62
|
+
|
63
|
+
it "adds a command to the command list if the updated command is on the parent class" do
|
64
|
+
expect(Scripts::MyScript.commands["example_default_command"]).to be
|
65
|
+
end
|
66
|
+
|
67
|
+
it "clones the parent command" do
|
68
|
+
expect(Scripts::MyScript.commands["example_default_command"]).not_to eq(MyChildScript.commands["example_default_command"])
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "#default_command" do
|
75
|
+
it "sets a default command" do
|
76
|
+
expect(MyScript.default_command).to eq("example_default_command")
|
77
|
+
end
|
78
|
+
|
79
|
+
it "invokes the default command if no command is specified" do
|
80
|
+
expect(MyScript.start([])).to eq("default command")
|
81
|
+
end
|
82
|
+
|
83
|
+
it "invokes the default command if no command is specified even if switches are given" do
|
84
|
+
expect(MyScript.start(["--with", "option"])).to eq({"with"=>"option"})
|
85
|
+
end
|
86
|
+
|
87
|
+
it "inherits the default command from parent" do
|
88
|
+
expect(MyChildScript.default_command).to eq("example_default_command")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "#stop_on_unknown_option!" do
|
93
|
+
my_script = Class.new(Thor) do
|
94
|
+
class_option "verbose", :type => :boolean
|
95
|
+
class_option "mode", :type => :string
|
96
|
+
|
97
|
+
stop_on_unknown_option! :exec
|
98
|
+
|
99
|
+
desc "exec", "Run a command"
|
100
|
+
def exec(*args)
|
101
|
+
return options, args
|
102
|
+
end
|
103
|
+
|
104
|
+
desc "boring", "An ordinary command"
|
105
|
+
def boring(*args)
|
106
|
+
return options, args
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
it "passes remaining args to command when it encounters a non-option" do
|
111
|
+
expect(my_script.start(%w[exec command --verbose])).to eq [{}, ["command", "--verbose"]]
|
112
|
+
end
|
113
|
+
|
114
|
+
it "passes remaining args to command when it encounters an unknown option" do
|
115
|
+
expect(my_script.start(%w[exec --foo command --bar])).to eq [{}, ["--foo", "command", "--bar"]]
|
116
|
+
end
|
117
|
+
|
118
|
+
it "still accepts options that are given before non-options" do
|
119
|
+
expect(my_script.start(%w[exec --verbose command --foo])).to eq [{"verbose" => true}, ["command", "--foo"]]
|
120
|
+
end
|
121
|
+
|
122
|
+
it "still accepts options that require a value" do
|
123
|
+
expect(my_script.start(%w[exec --mode rashly command])).to eq [{"mode" => "rashly"}, ["command"]]
|
124
|
+
end
|
125
|
+
|
126
|
+
it "still passes everything after -- to command" do
|
127
|
+
expect(my_script.start(%w[exec -- --verbose])).to eq [{}, ["--verbose"]]
|
128
|
+
end
|
129
|
+
|
130
|
+
it "does not affect ordinary commands" do
|
131
|
+
expect(my_script.start(%w[boring command --verbose])).to eq [{"verbose" => true}, ["command"]]
|
132
|
+
end
|
133
|
+
|
134
|
+
context "when provided with multiple command names" do
|
135
|
+
klass = Class.new(Thor) do
|
136
|
+
stop_on_unknown_option! :foo, :bar
|
137
|
+
end
|
138
|
+
it "affects all specified commands" do
|
139
|
+
expect(klass.stop_on_unknown_option?(double(:name => "foo"))).to be_true
|
140
|
+
expect(klass.stop_on_unknown_option?(double(:name => "bar"))).to be_true
|
141
|
+
expect(klass.stop_on_unknown_option?(double(:name => "baz"))).to be_false
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context "when invoked several times" do
|
146
|
+
klass = Class.new(Thor) do
|
147
|
+
stop_on_unknown_option! :foo
|
148
|
+
stop_on_unknown_option! :bar
|
149
|
+
end
|
150
|
+
it "affects all specified commands" do
|
151
|
+
expect(klass.stop_on_unknown_option?(double(:name => "foo"))).to be_true
|
152
|
+
expect(klass.stop_on_unknown_option?(double(:name => "bar"))).to be_true
|
153
|
+
expect(klass.stop_on_unknown_option?(double(:name => "baz"))).to be_false
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
it "doesn't break new" do
|
158
|
+
expect(my_script.new).to be_a(Thor)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
describe "#map" do
|
163
|
+
it "calls the alias of a method if one is provided" do
|
164
|
+
expect(MyScript.start(["-T", "fish"])).to eq(["fish"])
|
165
|
+
end
|
166
|
+
|
167
|
+
it "calls the alias of a method if several are provided via #map" do
|
168
|
+
expect(MyScript.start(["-f", "fish"])).to eq(["fish", {}])
|
169
|
+
expect(MyScript.start(["--foo", "fish"])).to eq(["fish", {}])
|
170
|
+
end
|
171
|
+
|
172
|
+
it "inherits all mappings from parent" do
|
173
|
+
expect(MyChildScript.default_command).to eq("example_default_command")
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
describe "#package_name" do
|
178
|
+
it "provides a proper description for a command when the package_name is assigned" do
|
179
|
+
content = capture(:stdout) { PackageNameScript.start(["help"]) }
|
180
|
+
expect(content).to match(/Baboon commands:/m)
|
181
|
+
end
|
182
|
+
|
183
|
+
# TODO: remove this, might be redundant, just wanted to prove full coverage
|
184
|
+
it "provides a proper description for a command when the package_name is NOT assigned" do
|
185
|
+
content = capture(:stdout) { MyScript.start(["help"]) }
|
186
|
+
expect(content).to match(/Commands:/m)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe "#desc" do
|
191
|
+
it "provides description for a command" do
|
192
|
+
content = capture(:stdout) { MyScript.start(["help"]) }
|
193
|
+
expect(content).to match(/thor my_script:zoo\s+# zoo around/m)
|
194
|
+
end
|
195
|
+
|
196
|
+
it "provides no namespace if $thor_runner is false" do
|
197
|
+
begin
|
198
|
+
$thor_runner = false
|
199
|
+
content = capture(:stdout) { MyScript.start(["help"]) }
|
200
|
+
expect(content).to match(/thor zoo\s+# zoo around/m)
|
201
|
+
ensure
|
202
|
+
$thor_runner = true
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
describe "when :for is supplied" do
|
207
|
+
it "overwrites a previous defined command" do
|
208
|
+
expect(capture(:stdout) { MyChildScript.start(["help"]) }).to match(/animal KIND \s+# fish around/m)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
describe "when :hide is supplied" do
|
213
|
+
it "does not show the command in help" do
|
214
|
+
expect(capture(:stdout) { MyScript.start(["help"]) }).not_to match(/this is hidden/m)
|
215
|
+
end
|
216
|
+
|
217
|
+
it "but the command is still invokable, does not show the command in help" do
|
218
|
+
expect(MyScript.start(["hidden", "yesyes"])).to eq(["yesyes"])
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
describe "#method_options" do
|
224
|
+
it "sets default options if called before an initializer" do
|
225
|
+
options = MyChildScript.class_options
|
226
|
+
expect(options[:force].type).to eq(:boolean)
|
227
|
+
expect(options[:param].type).to eq(:numeric)
|
228
|
+
end
|
229
|
+
|
230
|
+
it "overwrites default options if called on the method scope" do
|
231
|
+
args = ["zoo", "--force", "--param", "feathers"]
|
232
|
+
options = MyChildScript.start(args)
|
233
|
+
expect(options).to eq({ "force" => true, "param" => "feathers" })
|
234
|
+
end
|
235
|
+
|
236
|
+
it "allows default options to be merged with method options" do
|
237
|
+
args = ["animal", "bird", "--force", "--param", "1.0", "--other", "tweets"]
|
238
|
+
arg, options = MyChildScript.start(args)
|
239
|
+
expect(arg).to eq('bird')
|
240
|
+
expect(options).to eq({ "force"=>true, "param"=>1.0, "other"=>"tweets" })
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
describe "#start" do
|
245
|
+
it "calls a no-param method when no params are passed" do
|
246
|
+
expect(MyScript.start(["zoo"])).to eq(true)
|
247
|
+
end
|
248
|
+
|
249
|
+
it "calls a single-param method when a single param is passed" do
|
250
|
+
expect(MyScript.start(["animal", "fish"])).to eq(["fish"])
|
251
|
+
end
|
252
|
+
|
253
|
+
it "does not set options in attributes" do
|
254
|
+
expect(MyScript.start(["with_optional", "--all"])).to eq([nil, { "all" => true }, []])
|
255
|
+
end
|
256
|
+
|
257
|
+
it "raises an error if the wrong number of params are provided" do
|
258
|
+
arity_asserter = lambda do |args, msg|
|
259
|
+
stderr = capture(:stderr) { Scripts::Arities.start(args) }
|
260
|
+
expect(stderr.strip).to eq(msg)
|
261
|
+
end
|
262
|
+
arity_asserter.call ["zero_args", "one" ], %Q'ERROR: "thor zero_args" was called with arguments ["one"]\nUsage: "thor scripts:arities:zero_args"'
|
263
|
+
arity_asserter.call ["one_arg" ], %Q'ERROR: "thor one_arg" was called with no arguments\nUsage: "thor scripts:arities:one_arg ARG"'
|
264
|
+
arity_asserter.call ["one_arg", "one", "two" ], %Q'ERROR: "thor one_arg" was called with arguments ["one", "two"]\nUsage: "thor scripts:arities:one_arg ARG"'
|
265
|
+
arity_asserter.call ["one_arg", "one", "two" ], %Q'ERROR: "thor one_arg" was called with arguments ["one", "two"]\nUsage: "thor scripts:arities:one_arg ARG"'
|
266
|
+
arity_asserter.call ["two_args", "one" ], %Q'ERROR: "thor two_args" was called with arguments ["one"]\nUsage: "thor scripts:arities:two_args ARG1 ARG2"'
|
267
|
+
arity_asserter.call ["optional_arg", "one", "two" ], %Q'ERROR: "thor optional_arg" was called with arguments ["one", "two"]\nUsage: "thor scripts:arities:optional_arg [ARG]"'
|
268
|
+
end
|
269
|
+
|
270
|
+
it "raises an error if the invoked command does not exist" do
|
271
|
+
expect(capture(:stderr) { Amazing.start(["animal"]) }.strip).to eq('Could not find command "animal" in "amazing" namespace.')
|
272
|
+
end
|
273
|
+
|
274
|
+
it "calls method_missing if an unknown method is passed in" do
|
275
|
+
expect(MyScript.start(["unk", "hello"])).to eq([:unk, ["hello"]])
|
276
|
+
end
|
277
|
+
|
278
|
+
it "does not call a private method no matter what" do
|
279
|
+
expect(capture(:stderr) { MyScript.start(["what"]) }.strip).to eq('Could not find command "what" in "my_script" namespace.')
|
280
|
+
end
|
281
|
+
|
282
|
+
it "uses command default options" do
|
283
|
+
options = MyChildScript.start(["animal", "fish"]).last
|
284
|
+
expect(options).to eq({ "other" => "method default" })
|
285
|
+
end
|
286
|
+
|
287
|
+
it "raises when an exception happens within the command call" do
|
288
|
+
expect{ MyScript.start(["call_myself_with_wrong_arity"]) }.to raise_error(ArgumentError)
|
289
|
+
end
|
290
|
+
|
291
|
+
context "when the user enters an unambiguous substring of a command" do
|
292
|
+
it "invokes a command" do
|
293
|
+
expect(MyScript.start(["z"])).to eq(MyScript.start(["zoo"]))
|
294
|
+
end
|
295
|
+
|
296
|
+
it "invokes a command, even when there's an alias it resolves to the same command" do
|
297
|
+
expect(MyScript.start(["hi", "arg"])).to eq(MyScript.start(["hidden", "arg"]))
|
298
|
+
end
|
299
|
+
|
300
|
+
it "invokes an alias" do
|
301
|
+
expect(MyScript.start(["animal_pri"])).to eq(MyScript.start(["zoo"]))
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
context "when the user enters an ambiguous substring of a command" do
|
306
|
+
it "raises an exception and displays a message that explains the ambiguity" do
|
307
|
+
shell = Thor::Base.shell.new
|
308
|
+
expect(shell).to receive(:error).with('Ambiguous command call matches [call_myself_with_wrong_arity, call_unexistent_method]')
|
309
|
+
MyScript.start(["call"], :shell => shell)
|
310
|
+
end
|
311
|
+
|
312
|
+
it "raises an exception when there is an alias" do
|
313
|
+
shell = Thor::Base.shell.new
|
314
|
+
expect(shell).to receive(:error).with('Ambiguous command f matches [foo, fu]')
|
315
|
+
MyScript.start(["f"], :shell => shell)
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
end
|
320
|
+
|
321
|
+
describe "#help" do
|
322
|
+
def shell
|
323
|
+
@shell ||= Thor::Base.shell.new
|
324
|
+
end
|
325
|
+
|
326
|
+
describe "on general" do
|
327
|
+
before do
|
328
|
+
@content = capture(:stdout) { MyScript.help(shell) }
|
329
|
+
end
|
330
|
+
|
331
|
+
it "provides useful help info for the help method itself" do
|
332
|
+
expect(@content).to match(/help \[COMMAND\]\s+# Describe available commands/)
|
333
|
+
end
|
334
|
+
|
335
|
+
it "provides useful help info for a method with params" do
|
336
|
+
expect(@content).to match(/animal TYPE\s+# horse around/)
|
337
|
+
end
|
338
|
+
|
339
|
+
it "uses the maximum terminal size to show commands" do
|
340
|
+
expect(@shell).to receive(:terminal_width).and_return(80)
|
341
|
+
content = capture(:stdout) { MyScript.help(shell) }
|
342
|
+
expect(content).to match(/aaa\.\.\.$/)
|
343
|
+
end
|
344
|
+
|
345
|
+
it "provides description for commands from classes in the same namespace" do
|
346
|
+
expect(@content).to match(/baz\s+# do some bazing/)
|
347
|
+
end
|
348
|
+
|
349
|
+
it "shows superclass commands" do
|
350
|
+
content = capture(:stdout) { MyChildScript.help(shell) }
|
351
|
+
expect(content).to match(/foo BAR \s+# do some fooing/)
|
352
|
+
end
|
353
|
+
|
354
|
+
it "shows class options information" do
|
355
|
+
content = capture(:stdout) { MyChildScript.help(shell) }
|
356
|
+
expect(content).to match(/Options\:/)
|
357
|
+
expect(content).to match(/\[\-\-param=N\]/)
|
358
|
+
end
|
359
|
+
|
360
|
+
it "injects class arguments into default usage" do
|
361
|
+
content = capture(:stdout) { Scripts::MyScript.help(shell) }
|
362
|
+
expect(content).to match(/zoo ACCESSOR \-\-param\=PARAM/)
|
363
|
+
end
|
364
|
+
end
|
365
|
+
|
366
|
+
describe "for a specific command" do
|
367
|
+
it "provides full help info when talking about a specific command" do
|
368
|
+
expect(capture(:stdout) { MyScript.command_help(shell, "foo") }).to eq(<<-END)
|
369
|
+
Usage:
|
370
|
+
thor my_script:foo BAR
|
371
|
+
|
372
|
+
Options:
|
373
|
+
[--force] # Force to do some fooing
|
374
|
+
|
375
|
+
do some fooing
|
376
|
+
This is more info!
|
377
|
+
Everyone likes more info!
|
378
|
+
END
|
379
|
+
end
|
380
|
+
|
381
|
+
it "raises an error if the command can't be found" do
|
382
|
+
expect {
|
383
|
+
MyScript.command_help(shell, "unknown")
|
384
|
+
}.to raise_error(Thor::UndefinedCommandError, 'Could not find command "unknown" in "my_script" namespace.')
|
385
|
+
end
|
386
|
+
|
387
|
+
it "normalizes names before claiming they don't exist" do
|
388
|
+
expect(capture(:stdout) { MyScript.command_help(shell, "name-with-dashes") }).to match(/thor my_script:name-with-dashes/)
|
389
|
+
end
|
390
|
+
|
391
|
+
it "uses the long description if it exists" do
|
392
|
+
expect(capture(:stdout) { MyScript.command_help(shell, "long_description") }).to eq(<<-HELP)
|
393
|
+
Usage:
|
394
|
+
thor my_script:long_description
|
395
|
+
|
396
|
+
Description:
|
397
|
+
This is a really really really long description. Here you go. So very long.
|
398
|
+
|
399
|
+
It even has two paragraphs.
|
400
|
+
HELP
|
401
|
+
end
|
402
|
+
|
403
|
+
it "doesn't assign the long description to the next command without one" do
|
404
|
+
expect(capture(:stdout) {
|
405
|
+
MyScript.command_help(shell, "name_with_dashes")
|
406
|
+
}).not_to match(/so very long/i)
|
407
|
+
end
|
408
|
+
end
|
409
|
+
|
410
|
+
describe "instance method" do
|
411
|
+
it "calls the class method" do
|
412
|
+
expect(capture(:stdout) { MyScript.start(["help"]) }).to match(/Commands:/)
|
413
|
+
end
|
414
|
+
|
415
|
+
it "calls the class method" do
|
416
|
+
expect(capture(:stdout) { MyScript.start(["help", "foo"]) }).to match(/Usage:/)
|
417
|
+
end
|
418
|
+
end
|
419
|
+
end
|
420
|
+
|
421
|
+
describe "when creating commands" do
|
422
|
+
it "prints a warning if a public method is created without description or usage" do
|
423
|
+
expect(capture(:stdout) {
|
424
|
+
klass = Class.new(Thor)
|
425
|
+
klass.class_eval "def hello_from_thor; end"
|
426
|
+
}).to match(/\[WARNING\] Attempted to create command "hello_from_thor" without usage or description/)
|
427
|
+
end
|
428
|
+
|
429
|
+
it "does not print if overwriting a previous command" do
|
430
|
+
expect(capture(:stdout) {
|
431
|
+
klass = Class.new(Thor)
|
432
|
+
klass.class_eval "def help; end"
|
433
|
+
}).to be_empty
|
434
|
+
end
|
435
|
+
end
|
436
|
+
|
437
|
+
describe "edge-cases" do
|
438
|
+
it "can handle boolean options followed by arguments" do
|
439
|
+
klass = Class.new(Thor) do
|
440
|
+
method_option :loud, :type => :boolean
|
441
|
+
desc "hi NAME", "say hi to name"
|
442
|
+
def hi(name)
|
443
|
+
name.upcase! if options[:loud]
|
444
|
+
"Hi #{name}"
|
445
|
+
end
|
446
|
+
end
|
447
|
+
|
448
|
+
expect(klass.start(["hi", "jose"])).to eq("Hi jose")
|
449
|
+
expect(klass.start(["hi", "jose", "--loud"])).to eq("Hi JOSE")
|
450
|
+
expect(klass.start(["hi", "--loud", "jose"])).to eq("Hi JOSE")
|
451
|
+
end
|
452
|
+
|
453
|
+
it "passes through unknown options" do
|
454
|
+
klass = Class.new(Thor) do
|
455
|
+
desc "unknown", "passing unknown options"
|
456
|
+
def unknown(*args)
|
457
|
+
args
|
458
|
+
end
|
459
|
+
end
|
460
|
+
|
461
|
+
expect(klass.start(["unknown", "foo", "--bar", "baz", "bat", "--bam"])).to eq(["foo", "--bar", "baz", "bat", "--bam"])
|
462
|
+
expect(klass.start(["unknown", "--bar", "baz"])).to eq(["--bar", "baz"])
|
463
|
+
end
|
464
|
+
|
465
|
+
it "does not pass through unknown options with strict args" do
|
466
|
+
klass = Class.new(Thor) do
|
467
|
+
strict_args_position!
|
468
|
+
|
469
|
+
desc "unknown", "passing unknown options"
|
470
|
+
def unknown(*args)
|
471
|
+
args
|
472
|
+
end
|
473
|
+
end
|
474
|
+
|
475
|
+
expect(klass.start(["unknown", "--bar", "baz"])).to eq([])
|
476
|
+
expect(klass.start(["unknown", "foo", "--bar", "baz"])).to eq(["foo"])
|
477
|
+
end
|
478
|
+
|
479
|
+
it "strict args works in the inheritance chain" do
|
480
|
+
parent = Class.new(Thor) do
|
481
|
+
strict_args_position!
|
482
|
+
end
|
483
|
+
|
484
|
+
klass = Class.new(parent) do
|
485
|
+
desc "unknown", "passing unknown options"
|
486
|
+
def unknown(*args)
|
487
|
+
args
|
488
|
+
end
|
489
|
+
end
|
490
|
+
|
491
|
+
expect(klass.start(["unknown", "--bar", "baz"])).to eq([])
|
492
|
+
expect(klass.start(["unknown", "foo", "--bar", "baz"])).to eq(["foo"])
|
493
|
+
end
|
494
|
+
|
495
|
+
it "send as a command name" do
|
496
|
+
expect(MyScript.start(["send"])).to eq(true)
|
497
|
+
end
|
498
|
+
end
|
499
|
+
end
|
@@ -0,0 +1,196 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module Thor::Util
|
4
|
+
def self.clear_user_home!
|
5
|
+
@@user_home = nil
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Thor::Util do
|
10
|
+
describe "#find_by_namespace" do
|
11
|
+
it "returns 'default' if no namespace is given" do
|
12
|
+
expect(Thor::Util.find_by_namespace('')).to eq(Scripts::MyDefaults)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "adds 'default' if namespace starts with :" do
|
16
|
+
expect(Thor::Util.find_by_namespace(':child')).to eq(Scripts::ChildDefault)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns nil if the namespace can't be found" do
|
20
|
+
expect(Thor::Util.find_by_namespace('thor:core_ext:ordered_hash')).to be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns a class if it matches the namespace" do
|
24
|
+
expect(Thor::Util.find_by_namespace('app:broken:counter')).to eq(BrokenCounter)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "matches classes default namespace" do
|
28
|
+
expect(Thor::Util.find_by_namespace('scripts:my_script')).to eq(Scripts::MyScript)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#namespace_from_thor_class" do
|
33
|
+
it "replaces constant nesting with command namespacing" do
|
34
|
+
expect(Thor::Util.namespace_from_thor_class("Foo::Bar::Baz")).to eq("foo:bar:baz")
|
35
|
+
end
|
36
|
+
|
37
|
+
it "snake-cases component strings" do
|
38
|
+
expect(Thor::Util.namespace_from_thor_class("FooBar::BarBaz::BazBoom")).to eq("foo_bar:bar_baz:baz_boom")
|
39
|
+
end
|
40
|
+
|
41
|
+
it "accepts class and module objects" do
|
42
|
+
expect(Thor::Util.namespace_from_thor_class(Thor::CoreExt::OrderedHash)).to eq("thor:core_ext:ordered_hash")
|
43
|
+
expect(Thor::Util.namespace_from_thor_class(Thor::Util)).to eq("thor:util")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "removes Thor::Sandbox namespace" do
|
47
|
+
expect(Thor::Util.namespace_from_thor_class("Thor::Sandbox::Package")).to eq("package")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#namespaces_in_content" do
|
52
|
+
it "returns an array of names of constants defined in the string" do
|
53
|
+
list = Thor::Util.namespaces_in_content("class Foo; class Bar < Thor; end; end; class Baz; class Bat; end; end")
|
54
|
+
expect(list).to include("foo:bar")
|
55
|
+
expect(list).not_to include("bar:bat")
|
56
|
+
end
|
57
|
+
|
58
|
+
it "doesn't put the newly-defined constants in the enclosing namespace" do
|
59
|
+
Thor::Util.namespaces_in_content("class Blat; end")
|
60
|
+
expect(defined?(Blat)).not_to be
|
61
|
+
expect(defined?(Thor::Sandbox::Blat)).to be
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "#snake_case" do
|
66
|
+
it "preserves no-cap strings" do
|
67
|
+
expect(Thor::Util.snake_case("foo")).to eq("foo")
|
68
|
+
expect(Thor::Util.snake_case("foo_bar")).to eq("foo_bar")
|
69
|
+
end
|
70
|
+
|
71
|
+
it "downcases all-caps strings" do
|
72
|
+
expect(Thor::Util.snake_case("FOO")).to eq("foo")
|
73
|
+
expect(Thor::Util.snake_case("FOO_BAR")).to eq("foo_bar")
|
74
|
+
end
|
75
|
+
|
76
|
+
it "downcases initial-cap strings" do
|
77
|
+
expect(Thor::Util.snake_case("Foo")).to eq("foo")
|
78
|
+
end
|
79
|
+
|
80
|
+
it "replaces camel-casing with underscores" do
|
81
|
+
expect(Thor::Util.snake_case("FooBarBaz")).to eq("foo_bar_baz")
|
82
|
+
expect(Thor::Util.snake_case("Foo_BarBaz")).to eq("foo_bar_baz")
|
83
|
+
end
|
84
|
+
|
85
|
+
it "places underscores between multiple capitals" do
|
86
|
+
expect(Thor::Util.snake_case("ABClass")).to eq("a_b_class")
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "#find_class_and_command_by_namespace" do
|
91
|
+
it "returns a Thor::Group class if full namespace matches" do
|
92
|
+
expect(Thor::Util.find_class_and_command_by_namespace("my_counter")).to eq([MyCounter, nil])
|
93
|
+
end
|
94
|
+
|
95
|
+
it "returns a Thor class if full namespace matches" do
|
96
|
+
expect(Thor::Util.find_class_and_command_by_namespace("thor")).to eq([Thor, nil])
|
97
|
+
end
|
98
|
+
|
99
|
+
it "returns a Thor class and the command name" do
|
100
|
+
expect(Thor::Util.find_class_and_command_by_namespace("thor:help")).to eq([Thor, "help"])
|
101
|
+
end
|
102
|
+
|
103
|
+
it "falls back in the namespace:command look up even if a full namespace does not match" do
|
104
|
+
Thor.const_set(:Help, Module.new)
|
105
|
+
expect(Thor::Util.find_class_and_command_by_namespace("thor:help")).to eq([Thor, "help"])
|
106
|
+
Thor.send :remove_const, :Help
|
107
|
+
end
|
108
|
+
|
109
|
+
it "falls back on the default namespace class if nothing else matches" do
|
110
|
+
expect(Thor::Util.find_class_and_command_by_namespace("test")).to eq([Scripts::MyDefaults, "test"])
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "#thor_classes_in" do
|
115
|
+
it "returns thor classes inside the given class" do
|
116
|
+
expect(Thor::Util.thor_classes_in(MyScript)).to eq([MyScript::AnotherScript])
|
117
|
+
expect(Thor::Util.thor_classes_in(MyScript::AnotherScript)).to be_empty
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "#user_home" do
|
122
|
+
before do
|
123
|
+
allow(ENV).to receive(:[])
|
124
|
+
Thor::Util.clear_user_home!
|
125
|
+
end
|
126
|
+
|
127
|
+
it "returns the user path if no variable is set on the environment" do
|
128
|
+
expect(Thor::Util.user_home).to eq(File.expand_path("~"))
|
129
|
+
end
|
130
|
+
|
131
|
+
it "returns the *nix system path if file cannot be expanded and separator does not exist" do
|
132
|
+
expect(File).to receive(:expand_path).with("~").and_raise(RuntimeError)
|
133
|
+
previous_value = File::ALT_SEPARATOR
|
134
|
+
capture(:stderr){ File.const_set(:ALT_SEPARATOR, false) }
|
135
|
+
expect(Thor::Util.user_home).to eq("/")
|
136
|
+
capture(:stderr){ File.const_set(:ALT_SEPARATOR, previous_value) }
|
137
|
+
end
|
138
|
+
|
139
|
+
it "returns the windows system path if file cannot be expanded and a separator exists" do
|
140
|
+
expect(File).to receive(:expand_path).with("~").and_raise(RuntimeError)
|
141
|
+
previous_value = File::ALT_SEPARATOR
|
142
|
+
capture(:stderr){ File.const_set(:ALT_SEPARATOR, true) }
|
143
|
+
expect(Thor::Util.user_home).to eq("C:/")
|
144
|
+
capture(:stderr){ File.const_set(:ALT_SEPARATOR, previous_value) }
|
145
|
+
end
|
146
|
+
|
147
|
+
it "returns HOME/.thor if set" do
|
148
|
+
allow(ENV).to receive(:[]).with("HOME").and_return("/home/user/")
|
149
|
+
expect(Thor::Util.user_home).to eq("/home/user/")
|
150
|
+
end
|
151
|
+
|
152
|
+
it "returns path with HOMEDRIVE and HOMEPATH if set" do
|
153
|
+
allow(ENV).to receive(:[]).with("HOMEDRIVE").and_return("D:/")
|
154
|
+
allow(ENV).to receive(:[]).with("HOMEPATH").and_return("Documents and Settings/James")
|
155
|
+
expect(Thor::Util.user_home).to eq("D:/Documents and Settings/James")
|
156
|
+
end
|
157
|
+
|
158
|
+
it "returns APPDATA/.thor if set" do
|
159
|
+
allow(ENV).to receive(:[]).with("APPDATA").and_return("/home/user/")
|
160
|
+
expect(Thor::Util.user_home).to eq("/home/user/")
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe "#thor_root_glob" do
|
165
|
+
before do
|
166
|
+
allow(ENV).to receive(:[])
|
167
|
+
Thor::Util.clear_user_home!
|
168
|
+
end
|
169
|
+
|
170
|
+
it "escapes globs in path" do
|
171
|
+
allow(ENV).to receive(:[]).with("HOME").and_return("/home/user{1}/")
|
172
|
+
expect(Dir).to receive(:[]).with("/home/user\\{1\\}/.thor/*").and_return([])
|
173
|
+
expect(Thor::Util.thor_root_glob).to eq([])
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
describe "#globs_for" do
|
178
|
+
it "escapes globs in path" do
|
179
|
+
expect(Thor::Util.globs_for("/home/apps{1}")).to eq([
|
180
|
+
"/home/apps\\{1\\}/Thorfile",
|
181
|
+
"/home/apps\\{1\\}/*.thor",
|
182
|
+
"/home/apps\\{1\\}/tasks/*.thor",
|
183
|
+
"/home/apps\\{1\\}/lib/tasks/*.thor"
|
184
|
+
])
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
describe "#escape_globs" do
|
189
|
+
it "escapes ? * { } [ ] glob characters" do
|
190
|
+
expect(Thor::Util.escape_globs("apps?")).to eq("apps\\?")
|
191
|
+
expect(Thor::Util.escape_globs("apps*")).to eq("apps\\*")
|
192
|
+
expect(Thor::Util.escape_globs("apps {1}")).to eq("apps \\{1\\}")
|
193
|
+
expect(Thor::Util.escape_globs("apps [1]")).to eq("apps \\[1\\]")
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|