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.
Files changed (154) hide show
  1. data/.gitignore +7 -0
  2. data/.ruby-version +1 -0
  3. data/.travis.yml +7 -0
  4. data/CONTRIBUTING.md +11 -0
  5. data/Gemfile +3 -0
  6. data/Gemfile.lock +55 -0
  7. data/Guardfile +5 -0
  8. data/LICENSE +19 -0
  9. data/README.md +149 -0
  10. data/Rakefile +1 -0
  11. data/acquia_toolbelt.gemspec +34 -0
  12. data/bin/acquia +9 -0
  13. data/lib/acquia_toolbelt/cli/api.rb +164 -0
  14. data/lib/acquia_toolbelt/cli/auth.rb +31 -0
  15. data/lib/acquia_toolbelt/cli/database.rb +237 -0
  16. data/lib/acquia_toolbelt/cli/deploy.rb +36 -0
  17. data/lib/acquia_toolbelt/cli/domain.rb +177 -0
  18. data/lib/acquia_toolbelt/cli/environment.rb +71 -0
  19. data/lib/acquia_toolbelt/cli/file.rb +31 -0
  20. data/lib/acquia_toolbelt/cli/server.rb +67 -0
  21. data/lib/acquia_toolbelt/cli/site.rb +28 -0
  22. data/lib/acquia_toolbelt/cli/ssh.rb +78 -0
  23. data/lib/acquia_toolbelt/cli/svn.rb +73 -0
  24. data/lib/acquia_toolbelt/cli/task.rb +74 -0
  25. data/lib/acquia_toolbelt/cli/ui.rb +44 -0
  26. data/lib/acquia_toolbelt/cli.rb +103 -0
  27. data/lib/acquia_toolbelt/error.rb +4 -0
  28. data/lib/acquia_toolbelt/thor.rb +95 -0
  29. data/lib/acquia_toolbelt/version.rb +3 -0
  30. data/lib/acquia_toolbelt.rb +4 -0
  31. data/lib/vendor/thor/CHANGELOG.md +139 -0
  32. data/lib/vendor/thor/Gemfile +20 -0
  33. data/lib/vendor/thor/LICENSE.md +20 -0
  34. data/lib/vendor/thor/README.md +35 -0
  35. data/lib/vendor/thor/lib/thor/actions/create_file.rb +105 -0
  36. data/lib/vendor/thor/lib/thor/actions/create_link.rb +60 -0
  37. data/lib/vendor/thor/lib/thor/actions/directory.rb +119 -0
  38. data/lib/vendor/thor/lib/thor/actions/empty_directory.rb +137 -0
  39. data/lib/vendor/thor/lib/thor/actions/file_manipulation.rb +317 -0
  40. data/lib/vendor/thor/lib/thor/actions/inject_into_file.rb +109 -0
  41. data/lib/vendor/thor/lib/thor/actions.rb +318 -0
  42. data/lib/vendor/thor/lib/thor/base.rb +654 -0
  43. data/lib/vendor/thor/lib/thor/command.rb +136 -0
  44. data/lib/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +80 -0
  45. data/lib/vendor/thor/lib/thor/core_ext/io_binary_read.rb +12 -0
  46. data/lib/vendor/thor/lib/thor/core_ext/ordered_hash.rb +100 -0
  47. data/lib/vendor/thor/lib/thor/error.rb +32 -0
  48. data/lib/vendor/thor/lib/thor/group.rb +282 -0
  49. data/lib/vendor/thor/lib/thor/invocation.rb +172 -0
  50. data/lib/vendor/thor/lib/thor/parser/argument.rb +74 -0
  51. data/lib/vendor/thor/lib/thor/parser/arguments.rb +171 -0
  52. data/lib/vendor/thor/lib/thor/parser/option.rb +121 -0
  53. data/lib/vendor/thor/lib/thor/parser/options.rb +218 -0
  54. data/lib/vendor/thor/lib/thor/parser.rb +4 -0
  55. data/lib/vendor/thor/lib/thor/rake_compat.rb +72 -0
  56. data/lib/vendor/thor/lib/thor/runner.rb +322 -0
  57. data/lib/vendor/thor/lib/thor/shell/basic.rb +422 -0
  58. data/lib/vendor/thor/lib/thor/shell/color.rb +148 -0
  59. data/lib/vendor/thor/lib/thor/shell/html.rb +127 -0
  60. data/lib/vendor/thor/lib/thor/shell.rb +88 -0
  61. data/lib/vendor/thor/lib/thor/util.rb +270 -0
  62. data/lib/vendor/thor/lib/thor/version.rb +3 -0
  63. data/lib/vendor/thor/lib/thor.rb +474 -0
  64. data/lib/vendor/thor/spec/actions/create_file_spec.rb +170 -0
  65. data/lib/vendor/thor/spec/actions/create_link_spec.rb +95 -0
  66. data/lib/vendor/thor/spec/actions/directory_spec.rb +169 -0
  67. data/lib/vendor/thor/spec/actions/empty_directory_spec.rb +129 -0
  68. data/lib/vendor/thor/spec/actions/file_manipulation_spec.rb +382 -0
  69. data/lib/vendor/thor/spec/actions/inject_into_file_spec.rb +135 -0
  70. data/lib/vendor/thor/spec/actions_spec.rb +331 -0
  71. data/lib/vendor/thor/spec/base_spec.rb +291 -0
  72. data/lib/vendor/thor/spec/command_spec.rb +80 -0
  73. data/lib/vendor/thor/spec/core_ext/hash_with_indifferent_access_spec.rb +48 -0
  74. data/lib/vendor/thor/spec/core_ext/ordered_hash_spec.rb +115 -0
  75. data/lib/vendor/thor/spec/exit_condition_spec.rb +19 -0
  76. data/lib/vendor/thor/spec/fixtures/application.rb +2 -0
  77. data/lib/vendor/thor/spec/fixtures/app{1}/README +3 -0
  78. data/lib/vendor/thor/spec/fixtures/bundle/execute.rb +6 -0
  79. data/lib/vendor/thor/spec/fixtures/bundle/main.thor +1 -0
  80. data/lib/vendor/thor/spec/fixtures/command.thor +10 -0
  81. data/lib/vendor/thor/spec/fixtures/doc/%file_name%.rb.tt +1 -0
  82. data/lib/vendor/thor/spec/fixtures/doc/COMMENTER +11 -0
  83. data/lib/vendor/thor/spec/fixtures/doc/README +3 -0
  84. data/lib/vendor/thor/spec/fixtures/doc/block_helper.rb +3 -0
  85. data/lib/vendor/thor/spec/fixtures/doc/components/.empty_directory +0 -0
  86. data/lib/vendor/thor/spec/fixtures/doc/config.rb +1 -0
  87. data/lib/vendor/thor/spec/fixtures/doc/config.yaml.tt +1 -0
  88. data/lib/vendor/thor/spec/fixtures/doc/excluding/%file_name%.rb.tt +1 -0
  89. data/lib/vendor/thor/spec/fixtures/enum.thor +10 -0
  90. data/lib/vendor/thor/spec/fixtures/group.thor +128 -0
  91. data/lib/vendor/thor/spec/fixtures/invoke.thor +118 -0
  92. data/lib/vendor/thor/spec/fixtures/path with spaces +0 -0
  93. data/lib/vendor/thor/spec/fixtures/preserve/script.sh +3 -0
  94. data/lib/vendor/thor/spec/fixtures/script.thor +220 -0
  95. data/lib/vendor/thor/spec/fixtures/subcommand.thor +17 -0
  96. data/lib/vendor/thor/spec/group_spec.rb +222 -0
  97. data/lib/vendor/thor/spec/helper.rb +67 -0
  98. data/lib/vendor/thor/spec/invocation_spec.rb +108 -0
  99. data/lib/vendor/thor/spec/parser/argument_spec.rb +53 -0
  100. data/lib/vendor/thor/spec/parser/arguments_spec.rb +66 -0
  101. data/lib/vendor/thor/spec/parser/option_spec.rb +202 -0
  102. data/lib/vendor/thor/spec/parser/options_spec.rb +400 -0
  103. data/lib/vendor/thor/spec/rake_compat_spec.rb +72 -0
  104. data/lib/vendor/thor/spec/register_spec.rb +197 -0
  105. data/lib/vendor/thor/spec/runner_spec.rb +241 -0
  106. data/lib/vendor/thor/spec/shell/basic_spec.rb +330 -0
  107. data/lib/vendor/thor/spec/shell/color_spec.rb +95 -0
  108. data/lib/vendor/thor/spec/shell/html_spec.rb +31 -0
  109. data/lib/vendor/thor/spec/shell_spec.rb +47 -0
  110. data/lib/vendor/thor/spec/subcommand_spec.rb +30 -0
  111. data/lib/vendor/thor/spec/thor_spec.rb +499 -0
  112. data/lib/vendor/thor/spec/util_spec.rb +196 -0
  113. data/lib/vendor/thor/thor.gemspec +24 -0
  114. data/script/release +50 -0
  115. data/script/setup_build +6 -0
  116. data/script/test +23 -0
  117. data/spec/auth_spec.rb +15 -0
  118. data/spec/cassettes/databases/all_databases.json +1 -0
  119. data/spec/cassettes/databases/copy_database_from_dev_to_stage.json +1 -0
  120. data/spec/cassettes/databases/create_a_database_backup.json +1 -0
  121. data/spec/cassettes/databases/create_a_new_database.json +1 -0
  122. data/spec/cassettes/databases/delete_a_database.json +1 -0
  123. data/spec/cassettes/databases/get_all_existing_databases.json +1 -0
  124. data/spec/cassettes/databases/list_all_database_backups.json +1 -0
  125. data/spec/cassettes/databases/view_database_instance_details.json +1 -0
  126. data/spec/cassettes/deploy/release_vcs_branch.json +1 -0
  127. data/spec/cassettes/domains/create_new_domain.json +1 -0
  128. data/spec/cassettes/domains/delete_a_domain.json +1 -0
  129. data/spec/cassettes/domains/get_all_existing_domains.json +1 -0
  130. data/spec/cassettes/domains/list_all_dev_domains.json +1 -0
  131. data/spec/cassettes/domains/move_from_dev_to_stage.json +1 -0
  132. data/spec/cassettes/domains/purge_varnish_cache.json +1 -0
  133. data/spec/cassettes/environments/all_environments.json +1 -0
  134. data/spec/cassettes/environments/disable_live_development.json +1 -0
  135. data/spec/cassettes/environments/enable_live_development.json +1 -0
  136. data/spec/cassettes/files/copy_from_dev_to_stage.json +1 -0
  137. data/spec/cassettes/servers/all_dev_servers.json +1 -0
  138. data/spec/cassettes/servers/all_prod_servers.json +1 -0
  139. data/spec/cassettes/sites/all_sites.json +1 -0
  140. data/spec/cassettes/ssh/all_sshkeys.json +1 -0
  141. data/spec/cassettes/svn/all_svnusers.json +1 -0
  142. data/spec/cassettes/tasks/all_tasks.json +1 -0
  143. data/spec/databases_spec.rb +78 -0
  144. data/spec/deploy_spec.rb +12 -0
  145. data/spec/domains_spec.rb +59 -0
  146. data/spec/environments_spec.rb +35 -0
  147. data/spec/files_spec.rb +11 -0
  148. data/spec/helper.rb +104 -0
  149. data/spec/servers_spec.rb +59 -0
  150. data/spec/sites_spec.rb +19 -0
  151. data/spec/ssh_spec.rb +19 -0
  152. data/spec/svn_spec.rb +11 -0
  153. data/spec/tasks_spec.rb +11 -0
  154. metadata +158 -4
@@ -0,0 +1,220 @@
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
+
@@ -0,0 +1,17 @@
1
+ module TestSubcommands
2
+
3
+ class Subcommand < Thor
4
+ desc "print_opt", "My method"
5
+ def print_opt
6
+ print options["opt"]
7
+ end
8
+ end
9
+
10
+ class Parent < Thor
11
+ class_option "opt"
12
+
13
+ desc "sub", "My subcommand"
14
+ subcommand "sub", Subcommand
15
+ end
16
+
17
+ end
@@ -0,0 +1,222 @@
1
+ require 'helper'
2
+
3
+ describe Thor::Group do
4
+ describe "command" do
5
+ it "allows to use private methods from parent class as commands" do
6
+ expect(ChildGroup.start).to eq(["bar", "foo", "baz"])
7
+ expect(ChildGroup.new.baz("bar")).to eq("bar")
8
+ end
9
+ end
10
+
11
+ describe "#start" do
12
+ it "invokes all the commands under the Thor group" do
13
+ expect(MyCounter.start(["1", "2", "--third", "3"])).to eq([ 1, 2, 3, nil, nil, nil ])
14
+ end
15
+
16
+ it "uses argument's default value" do
17
+ expect(MyCounter.start(["1", "--third", "3"])).to eq([ 1, 2, 3, nil, nil, nil ])
18
+ end
19
+
20
+ it "invokes all the commands in the Thor group and its parents" do
21
+ expect(BrokenCounter.start(["1", "2", "--third", "3"])).to eq([ nil, 2, 3, false, 5, nil ])
22
+ end
23
+
24
+ it "raises an error if a required argument is added after a non-required" do
25
+ expect {
26
+ MyCounter.argument(:foo, :type => :string)
27
+ }.to raise_error(ArgumentError, 'You cannot have "foo" as required argument after the non-required argument "second".')
28
+ end
29
+
30
+ it "raises when an exception happens within the command call" do
31
+ expect{ BrokenCounter.start(["1", "2", "--fail"]) }.to raise_error
32
+ end
33
+
34
+ it "raises an error when a Thor group command expects arguments" do
35
+ expect{ WhinyGenerator.start }.to raise_error(ArgumentError, /thor wrong_arity takes 1 argument, but it should not/)
36
+ end
37
+
38
+ it "invokes help message if any of the shortcuts are given" do
39
+ expect(MyCounter).to receive(:help)
40
+ MyCounter.start(["-h"])
41
+ end
42
+ end
43
+
44
+ describe "#desc" do
45
+ it "sets the description for a given class" do
46
+ expect(MyCounter.desc).to eq("Description:\n This generator runs three commands: one, two and three.\n")
47
+ end
48
+
49
+ it "can be inherited" do
50
+ expect(BrokenCounter.desc).to eq("Description:\n This generator runs three commands: one, two and three.\n")
51
+ end
52
+
53
+ it "can be nil" do
54
+ expect(WhinyGenerator.desc).to be_nil
55
+ end
56
+ end
57
+
58
+ describe "#help" do
59
+ before do
60
+ @content = capture(:stdout) { MyCounter.help(Thor::Base.shell.new) }
61
+ end
62
+
63
+ it "provides usage information" do
64
+ expect(@content).to match(/my_counter N \[N\]/)
65
+ end
66
+
67
+ it "shows description" do
68
+ expect(@content).to match(/Description:/)
69
+ expect(@content).to match(/This generator runs three commands: one, two and three./)
70
+ end
71
+
72
+ it "shows options information" do
73
+ expect(@content).to match(/Options/)
74
+ expect(@content).to match(/\[\-\-third=THREE\]/)
75
+ end
76
+ end
77
+
78
+ describe "#invoke" do
79
+ before do
80
+ @content = capture(:stdout) { E.start }
81
+ end
82
+
83
+ it "allows to invoke a class from the class binding" do
84
+ expect(@content).to match(/1\n2\n3\n4\n5\n/)
85
+ end
86
+
87
+ it "shows invocation information to the user" do
88
+ expect(@content).to match(/invoke Defined/)
89
+ end
90
+
91
+ it "uses padding on status generated by the invoked class" do
92
+ expect(@content).to match(/finished counting/)
93
+ end
94
+
95
+ it "allows invocation to be configured with blocks" do
96
+ capture(:stdout) do
97
+ expect(F.start).to eq(["Valim, Jose"])
98
+ end
99
+ end
100
+
101
+ it "shows invoked options on help" do
102
+ content = capture(:stdout) { E.help(Thor::Base.shell.new) }
103
+ expect(content).to match(/Defined options:/)
104
+ expect(content).to match(/\[--unused\]/)
105
+ expect(content).to match(/# This option has no use/)
106
+ end
107
+ end
108
+
109
+ describe "#invoke_from_option" do
110
+ describe "with default type" do
111
+ before do
112
+ @content = capture(:stdout) { G.start }
113
+ end
114
+
115
+ it "allows to invoke a class from the class binding by a default option" do
116
+ expect(@content).to match(/1\n2\n3\n4\n5\n/)
117
+ end
118
+
119
+ it "does not invoke if the option is nil" do
120
+ expect(capture(:stdout) { G.start(["--skip-invoked"]) }).not_to match(/invoke/)
121
+ end
122
+
123
+ it "prints a message if invocation cannot be found" do
124
+ content = capture(:stdout) { G.start(["--invoked", "unknown"]) }
125
+ expect(content).to match(/error unknown \[not found\]/)
126
+ end
127
+
128
+ it "allows to invoke a class from the class binding by the given option" do
129
+ error = nil
130
+ content = capture(:stdout) {
131
+ error = capture(:stderr) {
132
+ G.start(["--invoked", "e"])
133
+ }
134
+ }
135
+ expect(content).to match(/invoke e/)
136
+ expect(error).to match(/ERROR: "thor two" was called with arguments/)
137
+ end
138
+
139
+ it "shows invocation information to the user" do
140
+ expect(@content).to match(/invoke defined/)
141
+ end
142
+
143
+ it "uses padding on status generated by the invoked class" do
144
+ expect(@content).to match(/finished counting/)
145
+ end
146
+
147
+ it "shows invoked options on help" do
148
+ content = capture(:stdout) { G.help(Thor::Base.shell.new) }
149
+ expect(content).to match(/defined options:/)
150
+ expect(content).to match(/\[--unused\]/)
151
+ expect(content).to match(/# This option has no use/)
152
+ end
153
+ end
154
+
155
+ describe "with boolean type" do
156
+ before do
157
+ @content = capture(:stdout) { H.start }
158
+ end
159
+
160
+ it "allows to invoke a class from the class binding by a default option" do
161
+ expect(@content).to match(/1\n2\n3\n4\n5\n/)
162
+ end
163
+
164
+ it "does not invoke if the option is false" do
165
+ expect(capture(:stdout) { H.start(["--no-defined"]) }).not_to match(/invoke/)
166
+ end
167
+
168
+ it "shows invocation information to the user" do
169
+ expect(@content).to match(/invoke defined/)
170
+ end
171
+
172
+ it "uses padding on status generated by the invoked class" do
173
+ expect(@content).to match(/finished counting/)
174
+ end
175
+
176
+ it "shows invoked options on help" do
177
+ content = capture(:stdout) { H.help(Thor::Base.shell.new) }
178
+ expect(content).to match(/defined options:/)
179
+ expect(content).to match(/\[--unused\]/)
180
+ expect(content).to match(/# This option has no use/)
181
+ end
182
+ end
183
+ end
184
+
185
+ describe "edge-cases" do
186
+ it "can handle boolean options followed by arguments" do
187
+ klass = Class.new(Thor::Group) do
188
+ desc "say hi to name"
189
+ argument :name, :type => :string
190
+ class_option :loud, :type => :boolean
191
+
192
+ def hi
193
+ name.upcase! if options[:loud]
194
+ "Hi #{name}"
195
+ end
196
+ end
197
+
198
+ expect(klass.start(["jose"])).to eq(["Hi jose"])
199
+ expect(klass.start(["jose", "--loud"])).to eq(["Hi JOSE"])
200
+ expect(klass.start(["--loud", "jose"])).to eq(["Hi JOSE"])
201
+ end
202
+
203
+ it "provides extra args as `args`" do
204
+ klass = Class.new(Thor::Group) do
205
+ desc "say hi to name"
206
+ argument :name, :type => :string
207
+ class_option :loud, :type => :boolean
208
+
209
+ def hi
210
+ name.upcase! if options[:loud]
211
+ out = "Hi #{name}"
212
+ out << ": " << args.join(", ") unless args.empty?
213
+ out
214
+ end
215
+ end
216
+
217
+ expect(klass.start(["jose"])).to eq(["Hi jose"])
218
+ expect(klass.start(["jose", "--loud"])).to eq(["Hi JOSE"])
219
+ expect(klass.start(["--loud", "jose"])).to eq(["Hi JOSE"])
220
+ end
221
+ end
222
+ end
@@ -0,0 +1,67 @@
1
+ $TESTING=true
2
+
3
+ require 'simplecov'
4
+ require 'coveralls'
5
+
6
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
7
+ SimpleCov::Formatter::HTMLFormatter,
8
+ Coveralls::SimpleCov::Formatter
9
+ ]
10
+ SimpleCov.start
11
+
12
+ $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
13
+ require 'thor'
14
+ require 'thor/group'
15
+ require 'stringio'
16
+
17
+ require 'rdoc'
18
+ require 'rspec'
19
+ require 'diff/lcs' # You need diff/lcs installed to run specs (but not to run Thor).
20
+ require 'fakeweb' # You need fakeweb installed to run specs (but not to run Thor).
21
+
22
+ # Set shell to basic
23
+ $0 = "thor"
24
+ $thor_runner = true
25
+ ARGV.clear
26
+ Thor::Base.shell = Thor::Shell::Basic
27
+
28
+ # Load fixtures
29
+ load File.join(File.dirname(__FILE__), "fixtures", "enum.thor")
30
+ load File.join(File.dirname(__FILE__), "fixtures", "group.thor")
31
+ load File.join(File.dirname(__FILE__), "fixtures", "invoke.thor")
32
+ load File.join(File.dirname(__FILE__), "fixtures", "script.thor")
33
+ load File.join(File.dirname(__FILE__), "fixtures", "subcommand.thor")
34
+ load File.join(File.dirname(__FILE__), "fixtures", "command.thor")
35
+
36
+ RSpec.configure do |config|
37
+ config.before do
38
+ ARGV.replace []
39
+ end
40
+
41
+ config.expect_with :rspec do |c|
42
+ c.syntax = :expect
43
+ end
44
+
45
+ def capture(stream)
46
+ begin
47
+ stream = stream.to_s
48
+ eval "$#{stream} = StringIO.new"
49
+ yield
50
+ result = eval("$#{stream}").string
51
+ ensure
52
+ eval("$#{stream} = #{stream.upcase}")
53
+ end
54
+
55
+ result
56
+ end
57
+
58
+ def source_root
59
+ File.join(File.dirname(__FILE__), 'fixtures')
60
+ end
61
+
62
+ def destination_root
63
+ File.join(File.dirname(__FILE__), 'sandbox')
64
+ end
65
+
66
+ alias :silence :capture
67
+ end
@@ -0,0 +1,108 @@
1
+ require 'helper'
2
+ require 'thor/base'
3
+
4
+ describe Thor::Invocation do
5
+ describe "#invoke" do
6
+ it "invokes a command inside another command" do
7
+ expect(capture(:stdout) { A.new.invoke(:two) }).to eq("2\n3\n")
8
+ end
9
+
10
+ it "invokes a command just once" do
11
+ expect(capture(:stdout) { A.new.invoke(:one) }).to eq("1\n2\n3\n")
12
+ end
13
+
14
+ it "invokes a command just once even if they belongs to different classes" do
15
+ expect(capture(:stdout) { Defined.new.invoke(:one) }).to eq("1\n2\n3\n4\n5\n")
16
+ end
17
+
18
+ it "invokes a command with arguments" do
19
+ expect(A.new.invoke(:five, [5])).to be_true
20
+ expect(A.new.invoke(:five, [7])).to be_false
21
+ end
22
+
23
+ it "invokes the default command if none is given to a Thor class" do
24
+ content = capture(:stdout) { A.new.invoke("b") }
25
+ expect(content).to match(/Commands/)
26
+ expect(content).to match(/LAST_NAME/)
27
+ end
28
+
29
+ it "accepts a class as argument without a command to invoke" do
30
+ content = capture(:stdout) { A.new.invoke(B) }
31
+ expect(content).to match(/Commands/)
32
+ expect(content).to match(/LAST_NAME/)
33
+ end
34
+
35
+ it "accepts a class as argument with a command to invoke" do
36
+ base = A.new([], :last_name => "Valim")
37
+ expect(base.invoke(B, :one, ["Jose"])).to eq("Valim, Jose")
38
+ end
39
+
40
+ it "allows customized options to be given" do
41
+ base = A.new([], :last_name => "Wrong")
42
+ expect(base.invoke(B, :one, ["Jose"], :last_name => "Valim")).to eq("Valim, Jose")
43
+ end
44
+
45
+ it "reparses options in the new class" do
46
+ expect(A.start(["invoker", "--last-name", "Valim"])).to eq("Valim, Jose")
47
+ end
48
+
49
+ it "shares initialize options with invoked class" do
50
+ expect(A.new([], :foo => :bar).invoke("b:two")).to eq({ "foo" => :bar })
51
+ end
52
+
53
+ it "uses default options from invoked class if no matching arguments are given" do
54
+ expect(A.new([]).invoke("b:four")).to eq("default")
55
+ end
56
+
57
+ it "overrides default options if options are passed to the invoker" do
58
+ expect(A.new([], { :defaulted_value => "not default"}).invoke("b:four")).to eq("not default")
59
+ end
60
+
61
+ it "dump configuration values to be used in the invoked class" do
62
+ base = A.new
63
+ expect(base.invoke("b:three").shell).to eq(base.shell)
64
+ end
65
+
66
+ it "allow extra configuration values to be given" do
67
+ base, shell = A.new, Thor::Base.shell.new
68
+ expect(base.invoke("b:three", [], {}, :shell => shell).shell).to eq(shell)
69
+ end
70
+
71
+ it "invokes a Thor::Group and all of its commands" do
72
+ expect(capture(:stdout) { A.new.invoke(:c) }).to eq("1\n2\n3\n")
73
+ end
74
+
75
+ it "does not invoke a Thor::Group twice" do
76
+ base = A.new
77
+ silence(:stdout){ base.invoke(:c) }
78
+ expect(capture(:stdout) { base.invoke(:c) }).to be_empty
79
+ end
80
+
81
+ it "does not invoke any of Thor::Group commands twice" do
82
+ base = A.new
83
+ silence(:stdout){ base.invoke(:c) }
84
+ expect(capture(:stdout) { base.invoke("c:one") }).to be_empty
85
+ end
86
+
87
+ it "raises Thor::UndefinedCommandError if the command can't be found" do
88
+ expect {
89
+ A.new.invoke("foo:bar")
90
+ }.to raise_error(Thor::UndefinedCommandError)
91
+ end
92
+
93
+ it "raises Thor::UndefinedCommandError if the command can't be found even if all commands were already executed" do
94
+ base = C.new
95
+ silence(:stdout){ base.invoke_all }
96
+
97
+ expect {
98
+ base.invoke("foo:bar")
99
+ }.to raise_error(Thor::UndefinedCommandError)
100
+ end
101
+
102
+ it "raises an error if a non Thor class is given" do
103
+ expect {
104
+ A.new.invoke(Object)
105
+ }.to raise_error(RuntimeError, "Expected Thor class, got Object")
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,53 @@
1
+ require 'helper'
2
+ require 'thor/parser'
3
+
4
+ describe Thor::Argument do
5
+
6
+ def argument(name, options={})
7
+ @argument ||= Thor::Argument.new(name, options)
8
+ end
9
+
10
+ describe "errors" do
11
+ it "raises an error if name is not supplied" do
12
+ expect {
13
+ argument(nil)
14
+ }.to raise_error(ArgumentError, "Argument name can't be nil.")
15
+ end
16
+
17
+ it "raises an error if type is unknown" do
18
+ expect {
19
+ argument(:command, :type => :unknown)
20
+ }.to raise_error(ArgumentError, "Type :unknown is not valid for arguments.")
21
+ end
22
+
23
+ it "raises an error if argument is required and has default values" do
24
+ expect {
25
+ argument(:command, :type => :string, :default => "bar", :required => true)
26
+ }.to raise_error(ArgumentError, "An argument cannot be required and have default value.")
27
+ end
28
+
29
+ it "raises an error if enum isn't an array" do
30
+ expect {
31
+ argument(:command, :type => :string, :enum => "bar")
32
+ }.to raise_error(ArgumentError, "An argument cannot have an enum other than an array.")
33
+ end
34
+ end
35
+
36
+ describe "#usage" do
37
+ it "returns usage for string types" do
38
+ expect(argument(:foo, :type => :string).usage).to eq("FOO")
39
+ end
40
+
41
+ it "returns usage for numeric types" do
42
+ expect(argument(:foo, :type => :numeric).usage).to eq("N")
43
+ end
44
+
45
+ it "returns usage for array types" do
46
+ expect(argument(:foo, :type => :array).usage).to eq("one two three")
47
+ end
48
+
49
+ it "returns usage for hash types" do
50
+ expect(argument(:foo, :type => :hash).usage).to eq("key:value")
51
+ end
52
+ end
53
+ end