hammer_cli 3.7.0 → 3.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/hammer +1 -6
- data/doc/release_notes.md +15 -0
- data/lib/hammer_cli/help/builder.rb +1 -2
- data/lib/hammer_cli/i18n/find_task.rb +88 -0
- data/lib/hammer_cli/i18n.rb +4 -0
- data/lib/hammer_cli/options/normalizers.rb +2 -5
- data/lib/hammer_cli/settings.rb +7 -0
- data/lib/hammer_cli/task_helper.rb +84 -0
- data/lib/hammer_cli/testing/output_matchers.rb +1 -1
- data/lib/hammer_cli/utils.rb +1 -1
- data/lib/hammer_cli/version.rb +1 -1
- data/locale/Makefile.def +29 -7
- data/locale/ca/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/cs_CZ/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/de/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/en/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/en_GB/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/es/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/fr/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/it/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/ja/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/ka/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/ko/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/pt_BR/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/ru/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/zh_CN/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/zh_TW/LC_MESSAGES/hammer-cli.mo +0 -0
- data/man/hammer.1.gz +0 -0
- data/test/functional/help_test.rb +1 -1
- data/test/test_helper.rb +1 -1
- data/test/unit/abstract_test.rb +54 -54
- data/test/unit/apipie/command_test.rb +26 -27
- data/test/unit/apipie/option_builder_test.rb +28 -28
- data/test/unit/apipie/option_definition_test.rb +5 -5
- data/test/unit/apipie/test_helper.rb +3 -0
- data/test/unit/bash_test.rb +21 -21
- data/test/unit/command_extensions_test.rb +68 -68
- data/test/unit/completer_test.rb +57 -57
- data/test/unit/csv_parser_test.rb +12 -12
- data/test/unit/defaults_test.rb +3 -3
- data/test/unit/help/builder_test.rb +7 -7
- data/test/unit/help/definition/abstract_item_test.rb +2 -2
- data/test/unit/help/definition/list_test.rb +2 -2
- data/test/unit/help/definition/note_test.rb +2 -2
- data/test/unit/help/definition/section_test.rb +2 -2
- data/test/unit/help/definition/text_test.rb +2 -2
- data/test/unit/help/definition_test.rb +36 -36
- data/test/unit/help/text_builder_test.rb +39 -39
- data/test/unit/history_test.rb +6 -6
- data/test/unit/i18n_test.rb +2 -2
- data/test/unit/logger_test.rb +1 -1
- data/test/unit/main_test.rb +7 -7
- data/test/unit/modules_test.rb +24 -25
- data/test/unit/option_builder_test.rb +1 -1
- data/test/unit/options/matcher_test.rb +15 -15
- data/test/unit/options/normalizers_test.rb +92 -88
- data/test/unit/options/option_definition_test.rb +11 -11
- data/test/unit/options/option_family_test.rb +7 -7
- data/test/unit/options/validators/dsl_test.rb +35 -35
- data/test/unit/output/adapter/abstract_test.rb +10 -10
- data/test/unit/output/adapter/base_test.rb +36 -36
- data/test/unit/output/adapter/csv_test.rb +38 -38
- data/test/unit/output/adapter/json_test.rb +38 -38
- data/test/unit/output/adapter/table_test.rb +42 -50
- data/test/unit/output/adapter/yaml_test.rb +38 -38
- data/test/unit/output/definition_test.rb +43 -43
- data/test/unit/output/dsl_test.rb +19 -19
- data/test/unit/output/field_filter_test.rb +10 -10
- data/test/unit/output/fields_test.rb +27 -27
- data/test/unit/output/formatters_test.rb +39 -39
- data/test/unit/output/output_test.rb +14 -14
- data/test/unit/output/record_collection_test.rb +18 -18
- data/test/unit/settings_test.rb +35 -35
- data/test/unit/utils_test.rb +30 -27
- metadata +33 -44
data/test/unit/abstract_test.rb
CHANGED
@@ -8,15 +8,15 @@ describe HammerCLI::AbstractCommand do
|
|
8
8
|
let(:cmd_class) { Class.new(HammerCLI::AbstractCommand) }
|
9
9
|
let(:cmd) { cmd_class.new("", { :adapter => :silent }) }
|
10
10
|
it "should define adapter" do
|
11
|
-
cmd.adapter.must_equal :base
|
11
|
+
_(cmd.adapter).must_equal :base
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should provide instance of output with default adapter set" do
|
15
|
-
cmd.output.default_adapter.must_equal cmd.adapter
|
15
|
+
_(cmd.output.default_adapter).must_equal cmd.adapter
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should hold instance of output definition" do
|
19
|
-
cmd.output_definition.must_be_instance_of HammerCLI::Output::Definition
|
19
|
+
_(cmd.output_definition).must_be_instance_of HammerCLI::Output::Definition
|
20
20
|
end
|
21
21
|
|
22
22
|
it "can append existing definition" do
|
@@ -26,7 +26,7 @@ describe HammerCLI::AbstractCommand do
|
|
26
26
|
|
27
27
|
cmd_class.output(definition) do
|
28
28
|
end
|
29
|
-
cmd_class.output_definition.fields.length.must_equal definition.fields.length
|
29
|
+
_(cmd_class.output_definition.fields.length).must_equal definition.fields.length
|
30
30
|
end
|
31
31
|
|
32
32
|
it "can append existing definition without passing a block" do
|
@@ -35,7 +35,7 @@ describe HammerCLI::AbstractCommand do
|
|
35
35
|
definition.fields << Fields::Field.new
|
36
36
|
|
37
37
|
cmd_class.output(definition)
|
38
|
-
cmd_class.output_definition.fields.length.must_equal definition.fields.length
|
38
|
+
_(cmd_class.output_definition.fields.length).must_equal definition.fields.length
|
39
39
|
end
|
40
40
|
|
41
41
|
it "can define fields" do
|
@@ -43,7 +43,7 @@ describe HammerCLI::AbstractCommand do
|
|
43
43
|
field :test_1, "test 1"
|
44
44
|
field :test_2, "test 2"
|
45
45
|
end
|
46
|
-
cmd_class.output_definition.fields.length.must_equal 2
|
46
|
+
_(cmd_class.output_definition.fields.length).must_equal 2
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -66,19 +66,19 @@ describe HammerCLI::AbstractCommand do
|
|
66
66
|
|
67
67
|
it "should return instance of hammer cli exception handler by default" do
|
68
68
|
cmd = ModA::ModB::TestCmd.new ""
|
69
|
-
cmd.exception_handler.must_be_instance_of HammerCLI::ExceptionHandler
|
69
|
+
_(cmd.exception_handler).must_be_instance_of HammerCLI::ExceptionHandler
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should return instance of exception handler class defined in a module" do
|
73
73
|
ModA::ModB.expects(:exception_handler_class).returns(Handler)
|
74
74
|
cmd = ModA::ModB::TestCmd.new ""
|
75
|
-
cmd.exception_handler.must_be_instance_of Handler
|
75
|
+
_(cmd.exception_handler).must_be_instance_of Handler
|
76
76
|
end
|
77
77
|
|
78
78
|
it "should return instance of exception handler class defined deeper in a module hierrarchy" do
|
79
79
|
ModA.expects(:exception_handler_class).returns(Handler)
|
80
80
|
cmd = ModA::ModB::TestCmd.new ""
|
81
|
-
cmd.exception_handler.must_be_instance_of Handler
|
81
|
+
_(cmd.exception_handler).must_be_instance_of Handler
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
@@ -94,7 +94,7 @@ describe HammerCLI::AbstractCommand do
|
|
94
94
|
it "should log what has been executed" do
|
95
95
|
test_command = Class.new(HammerCLI::AbstractCommand).new("")
|
96
96
|
test_command.run []
|
97
|
-
@log_output.readline.strip.must_equal "INFO HammerCLI::AbstractCommand : Called with options: {}"
|
97
|
+
_(@log_output.readline.strip).must_equal "INFO HammerCLI::AbstractCommand : Called with options: {}"
|
98
98
|
end
|
99
99
|
|
100
100
|
|
@@ -108,7 +108,7 @@ describe HammerCLI::AbstractCommand do
|
|
108
108
|
it "should have logger named by the class by default" do
|
109
109
|
test_command = Class.new(TestLogCmd).new("")
|
110
110
|
test_command.run []
|
111
|
-
@log_output.read.must_include "ERROR TestLogCmd : Test"
|
111
|
+
_(@log_output.read).must_include "ERROR TestLogCmd : Test"
|
112
112
|
end
|
113
113
|
|
114
114
|
class TestLogCmd2 < HammerCLI::AbstractCommand
|
@@ -121,7 +121,7 @@ describe HammerCLI::AbstractCommand do
|
|
121
121
|
it "should have logger that accepts custom name" do
|
122
122
|
test_command = Class.new(TestLogCmd2).new("")
|
123
123
|
test_command.run []
|
124
|
-
@log_output.read.must_include "ERROR My logger : Test"
|
124
|
+
_(@log_output.read).must_include "ERROR My logger : Test"
|
125
125
|
end
|
126
126
|
|
127
127
|
class TestLogCmd3 < HammerCLI::AbstractCommand
|
@@ -134,7 +134,7 @@ describe HammerCLI::AbstractCommand do
|
|
134
134
|
it "should have logger that can inspect object" do
|
135
135
|
test_command = Class.new(TestLogCmd3).new("")
|
136
136
|
test_command.run []
|
137
|
-
@log_output.read.must_include "DEBUG TestLogCmd3 : Test\n{}"
|
137
|
+
_(@log_output.read).must_include "DEBUG TestLogCmd3 : Test\n{}"
|
138
138
|
end
|
139
139
|
|
140
140
|
class TestLogCmd4 < HammerCLI::AbstractCommand
|
@@ -147,7 +147,7 @@ describe HammerCLI::AbstractCommand do
|
|
147
147
|
it "should have logger.watch output without colors" do
|
148
148
|
test_command = Class.new(TestLogCmd4).new("")
|
149
149
|
test_command.run []
|
150
|
-
@log_output.read.must_include "DEBUG TestLogCmd4 : Test\n{\n :a => \"a\"\n}"
|
150
|
+
_(@log_output.read).must_include "DEBUG TestLogCmd4 : Test\n{\n :a => \"a\"\n}"
|
151
151
|
end
|
152
152
|
|
153
153
|
class TestLogCmd5 < HammerCLI::AbstractCommand
|
@@ -162,7 +162,7 @@ describe HammerCLI::AbstractCommand do
|
|
162
162
|
HammerCLI::Settings.clear
|
163
163
|
HammerCLI::Settings.load(:watch_plain => true)
|
164
164
|
test_command.run []
|
165
|
-
@log_output.read.must_include "DEBUG TestLogCmd5 : Test\n{\n :a => \"a\"\n}"
|
165
|
+
_(@log_output.read).must_include "DEBUG TestLogCmd5 : Test\n{\n :a => \"a\"\n}"
|
166
166
|
end
|
167
167
|
|
168
168
|
class TestLogCmd6 < HammerCLI::AbstractCommand
|
@@ -177,7 +177,7 @@ describe HammerCLI::AbstractCommand do
|
|
177
177
|
HammerCLI::Settings.clear
|
178
178
|
HammerCLI::Settings.load(:watch_plain => true)
|
179
179
|
test_command.run []
|
180
|
-
@log_output.read.must_include "DEBUG TestLogCmd6 : Test\n{\n :password => \"***\",\n \"password\" => \"***\"\n}"
|
180
|
+
_(@log_output.read).must_include "DEBUG TestLogCmd6 : Test\n{\n :password => \"***\",\n \"password\" => \"***\"\n}"
|
181
181
|
end
|
182
182
|
|
183
183
|
it "password parameters should be hidden in logs" do
|
@@ -185,7 +185,7 @@ describe HammerCLI::AbstractCommand do
|
|
185
185
|
test_command_class.option(['--password'], 'PASSWORD', 'Password')
|
186
186
|
test_command = test_command_class.new("")
|
187
187
|
test_command.run ['--password=pass']
|
188
|
-
@log_output.readline.strip.must_equal "INFO HammerCLI::AbstractCommand : Called with options: {\"option_password\"=>\"***\"}"
|
188
|
+
_(@log_output.readline.strip).must_equal "INFO HammerCLI::AbstractCommand : Called with options: {\"option_password\"=>\"***\"}"
|
189
189
|
end
|
190
190
|
end
|
191
191
|
|
@@ -209,24 +209,24 @@ describe HammerCLI::AbstractCommand do
|
|
209
209
|
|
210
210
|
it "should replace commands with the same name" do
|
211
211
|
main_cmd.subcommand!("ping", "description", Subcommand2)
|
212
|
-
main_cmd.find_subcommand("some_command").wont_be_nil
|
213
|
-
main_cmd.find_subcommand("ping").wont_be_nil
|
214
|
-
main_cmd.find_subcommand("ping").subcommand_class.must_equal Subcommand2
|
215
|
-
main_cmd.recognised_subcommands.count.must_equal 2
|
212
|
+
_(main_cmd.find_subcommand("some_command")).wont_be_nil
|
213
|
+
_(main_cmd.find_subcommand("ping")).wont_be_nil
|
214
|
+
_(main_cmd.find_subcommand("ping").subcommand_class).must_equal Subcommand2
|
215
|
+
_(main_cmd.recognised_subcommands.count).must_equal 2
|
216
216
|
end
|
217
217
|
|
218
218
|
it "should write a message to log when replacing subcommand" do
|
219
219
|
main_cmd.subcommand!("ping", "description", Subcommand2)
|
220
|
-
@log_output.readline.strip.must_equal "INFO Clamp::Command : subcommand ping (Subcommand1) was removed."
|
221
|
-
@log_output.readline.strip.must_equal "INFO Clamp::Command : subcommand ping (Subcommand2) was created."
|
220
|
+
_(@log_output.readline.strip).must_equal "INFO Clamp::Command : subcommand ping (Subcommand1) was removed."
|
221
|
+
_(@log_output.readline.strip).must_equal "INFO Clamp::Command : subcommand ping (Subcommand2) was created."
|
222
222
|
end
|
223
223
|
|
224
224
|
it "should add the subcommand" do
|
225
225
|
main_cmd.subcommand!("new_command", "description", Subcommand2)
|
226
|
-
main_cmd.find_subcommand("new_command").wont_be_nil
|
227
|
-
main_cmd.find_subcommand("some_command").wont_be_nil
|
228
|
-
main_cmd.find_subcommand("ping").wont_be_nil
|
229
|
-
main_cmd.recognised_subcommands.count.must_equal 3
|
226
|
+
_(main_cmd.find_subcommand("new_command")).wont_be_nil
|
227
|
+
_(main_cmd.find_subcommand("some_command")).wont_be_nil
|
228
|
+
_(main_cmd.find_subcommand("ping")).wont_be_nil
|
229
|
+
_(main_cmd.recognised_subcommands.count).must_equal 3
|
230
230
|
end
|
231
231
|
|
232
232
|
end
|
@@ -235,17 +235,17 @@ describe HammerCLI::AbstractCommand do
|
|
235
235
|
describe "subcommand" do
|
236
236
|
|
237
237
|
it "should throw an exception for conflicting commands" do
|
238
|
-
|
238
|
+
_{
|
239
239
|
main_cmd.subcommand("ping", "description", Subcommand2)
|
240
|
-
|
240
|
+
}.must_raise HammerCLI::CommandConflict
|
241
241
|
end
|
242
242
|
|
243
243
|
it "should add the subcommand" do
|
244
244
|
main_cmd.subcommand("new_command", "description", Subcommand2)
|
245
|
-
main_cmd.find_subcommand("new_command").wont_be_nil
|
246
|
-
main_cmd.find_subcommand("some_command").wont_be_nil
|
247
|
-
main_cmd.find_subcommand("ping").wont_be_nil
|
248
|
-
main_cmd.recognised_subcommands.count.must_equal 3
|
245
|
+
_(main_cmd.find_subcommand("new_command")).wont_be_nil
|
246
|
+
_(main_cmd.find_subcommand("some_command")).wont_be_nil
|
247
|
+
_(main_cmd.find_subcommand("ping")).wont_be_nil
|
248
|
+
_(main_cmd.recognised_subcommands.count).must_equal 3
|
249
249
|
end
|
250
250
|
|
251
251
|
end
|
@@ -253,34 +253,34 @@ describe HammerCLI::AbstractCommand do
|
|
253
253
|
describe "remove_subcommand" do
|
254
254
|
it "should remove the subcommand" do
|
255
255
|
main_cmd.remove_subcommand('ping')
|
256
|
-
main_cmd.find_subcommand("ping").must_be_nil
|
256
|
+
_(main_cmd.find_subcommand("ping")).must_be_nil
|
257
257
|
end
|
258
258
|
|
259
259
|
it "should write a message to log when removing subcommand" do
|
260
260
|
main_cmd.remove_subcommand('ping')
|
261
|
-
@log_output.readline.strip.must_equal "INFO Clamp::Command : subcommand ping (Subcommand1) was removed."
|
261
|
+
_(@log_output.readline.strip).must_equal "INFO Clamp::Command : subcommand ping (Subcommand1) was removed."
|
262
262
|
end
|
263
263
|
|
264
264
|
end
|
265
265
|
|
266
266
|
describe 'find_subcommand' do
|
267
267
|
it 'should find by full name' do
|
268
|
-
main_cmd.find_subcommand('some_command').wont_be_nil
|
268
|
+
_(main_cmd.find_subcommand('some_command')).wont_be_nil
|
269
269
|
end
|
270
270
|
|
271
271
|
it 'should find by partial name' do
|
272
|
-
main_cmd.find_subcommand('some_').wont_be_nil
|
272
|
+
_(main_cmd.find_subcommand('some_')).wont_be_nil
|
273
273
|
end
|
274
274
|
|
275
275
|
it 'should not find by wrong name' do
|
276
|
-
main_cmd.find_subcommand('not_existing').must_be_nil
|
276
|
+
_(main_cmd.find_subcommand('not_existing')).must_be_nil
|
277
277
|
end
|
278
278
|
|
279
279
|
it 'should raise if more than one were found' do
|
280
280
|
main_cmd.subcommand('pong', 'description', Subcommand2)
|
281
|
-
|
281
|
+
_{
|
282
282
|
main_cmd.find_subcommand('p')
|
283
|
-
|
283
|
+
}.must_raise HammerCLI::CommandConflict
|
284
284
|
end
|
285
285
|
end
|
286
286
|
end
|
@@ -296,22 +296,22 @@ describe HammerCLI::AbstractCommand do
|
|
296
296
|
|
297
297
|
it "should create instances of hammer options" do
|
298
298
|
opt = TestOptionCmd.find_option("--test")
|
299
|
-
opt.kind_of?(HammerCLI::Options::OptionDefinition).must_equal true
|
299
|
+
_(opt.kind_of?(HammerCLI::Options::OptionDefinition)).must_equal true
|
300
300
|
end
|
301
301
|
|
302
302
|
it "should set options' formatters" do
|
303
303
|
opt = TestOptionCmd.find_option("--test-format")
|
304
|
-
opt.value_formatter.kind_of?(HammerCLI::Options::Normalizers::List).must_equal true
|
304
|
+
_(opt.value_formatter.kind_of?(HammerCLI::Options::Normalizers::List)).must_equal true
|
305
305
|
end
|
306
306
|
|
307
307
|
it 'should allow using of predefined options' do
|
308
308
|
opt = TestOptionCmd.find_option('--fields')
|
309
|
-
opt.is_a?(HammerCLI::Options::OptionDefinition).must_equal true
|
309
|
+
_(opt.is_a?(HammerCLI::Options::OptionDefinition)).must_equal true
|
310
310
|
end
|
311
311
|
|
312
312
|
it 'should add option type and accepted value' do
|
313
313
|
help_str = TestOptionCmd.help('')
|
314
|
-
help_str.must_match(
|
314
|
+
_(help_str).must_match(
|
315
315
|
/LIST Comma separated list of values. Values containing comma should be quoted or escaped with backslash./
|
316
316
|
)
|
317
317
|
end
|
@@ -330,11 +330,11 @@ describe HammerCLI::AbstractCommand do
|
|
330
330
|
describe "option builder" do
|
331
331
|
|
332
332
|
it "uses builder container as default" do
|
333
|
-
HammerCLI::AbstractCommand.option_builder.class.must_equal HammerCLI::OptionBuilderContainer
|
333
|
+
_(HammerCLI::AbstractCommand.option_builder.class).must_equal HammerCLI::OptionBuilderContainer
|
334
334
|
end
|
335
335
|
|
336
336
|
it "Default builder container is empty" do
|
337
|
-
HammerCLI::AbstractCommand.option_builder.builders.empty
|
337
|
+
_(HammerCLI::AbstractCommand.option_builder.builders.empty?).must_equal true
|
338
338
|
end
|
339
339
|
|
340
340
|
end
|
@@ -368,13 +368,13 @@ describe HammerCLI::AbstractCommand do
|
|
368
368
|
|
369
369
|
it "should use option builder" do
|
370
370
|
TestBuilderCmd.build_options
|
371
|
-
TestBuilderCmd.recognised_options.map(&:switches).flatten.sort.must_equal ["--test", "--test2"].sort
|
371
|
+
_(TestBuilderCmd.recognised_options.map(&:switches).flatten.sort).must_equal ["--test", "--test2"].sort
|
372
372
|
end
|
373
373
|
|
374
374
|
it "should skip options that already exist" do
|
375
375
|
TestBuilderCmd.option(["--test"], "TEST", "original_test")
|
376
376
|
TestBuilderCmd.build_options
|
377
|
-
TestBuilderCmd.recognised_options.map(&:description).flatten.sort.must_equal ["original_test", "test2"].sort
|
377
|
+
_(TestBuilderCmd.recognised_options.map(&:description).flatten.sort).must_equal ["original_test", "test2"].sort
|
378
378
|
end
|
379
379
|
|
380
380
|
it "passes params to the builders" do
|
@@ -441,7 +441,7 @@ describe HammerCLI::AbstractCommand do
|
|
441
441
|
class CmdName2 < CmdName1
|
442
442
|
end
|
443
443
|
|
444
|
-
CmdName2.command_name.must_equal ['cmd']
|
444
|
+
_(CmdName2.command_name).must_equal ['cmd']
|
445
445
|
end
|
446
446
|
|
447
447
|
it "should inherit output definition" do
|
@@ -455,7 +455,7 @@ describe HammerCLI::AbstractCommand do
|
|
455
455
|
class CmdOD2 < CmdOD1
|
456
456
|
end
|
457
457
|
|
458
|
-
CmdOD2.output_definition.fields.length.must_equal 1
|
458
|
+
_(CmdOD2.output_definition.fields.length).must_equal 1
|
459
459
|
end
|
460
460
|
|
461
461
|
describe 'validate_options' do
|
@@ -551,14 +551,14 @@ describe HammerCLI::AbstractCommand do
|
|
551
551
|
it 'should extend command with option, output, help right away' do
|
552
552
|
cmd.extend_with(extension)
|
553
553
|
opt = cmd.find_option('--flag')
|
554
|
-
opt.is_a?(HammerCLI::Options::OptionDefinition).must_equal true
|
555
|
-
cmd.output_definition.empty
|
556
|
-
cmd.new('', {}).help.must_match(/.*text.*/)
|
554
|
+
_(opt.is_a?(HammerCLI::Options::OptionDefinition)).must_equal true
|
555
|
+
_(cmd.output_definition.empty?).must_equal false
|
556
|
+
_(cmd.new('', {}).help).must_match(/.*text.*/)
|
557
557
|
end
|
558
558
|
|
559
559
|
it 'should store more than one extension' do
|
560
560
|
cmd.extend_with(extension, output_extension)
|
561
|
-
cmd.command_extensions.size.must_equal 2
|
561
|
+
_(cmd.command_extensions.size).must_equal 2
|
562
562
|
end
|
563
563
|
end
|
564
564
|
end
|
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require_relative 'test_helper'
|
3
2
|
|
4
3
|
describe HammerCLI::Apipie::Command do
|
5
4
|
|
@@ -34,12 +33,12 @@ describe HammerCLI::Apipie::Command do
|
|
34
33
|
end
|
35
34
|
|
36
35
|
let(:ctx) { { :adapter => :silent, :interactive => false } }
|
37
|
-
let(:cmd_class) { HammerCLI::Apipie::Command
|
36
|
+
let(:cmd_class) { Class.new(HammerCLI::Apipie::Command) }
|
38
37
|
let(:cmd) { cmd_class.new("", ctx) }
|
39
38
|
let(:cmd_run) { cmd.run([]) }
|
40
39
|
|
41
40
|
context "unsupported commands" do
|
42
|
-
let(:cmd_class) { CommandUnsupp
|
41
|
+
let(:cmd_class) { Class.new(CommandUnsupp) }
|
43
42
|
let(:cmd) { cmd_class.new("unsupported", ctx) }
|
44
43
|
it "should print help for unsupported command" do
|
45
44
|
assert_match(/.*Unfortunately the server does not support such operation.*/, cmd.help)
|
@@ -52,63 +51,63 @@ describe HammerCLI::Apipie::Command do
|
|
52
51
|
it "should set resource and action together" do
|
53
52
|
cmd_class.resource :architectures, :index
|
54
53
|
|
55
|
-
cmd.resource.name.must_equal :architectures
|
56
|
-
cmd_class.resource.name.must_equal :architectures
|
54
|
+
_(cmd.resource.name).must_equal :architectures
|
55
|
+
_(cmd_class.resource.name).must_equal :architectures
|
57
56
|
|
58
|
-
cmd.action.must_equal :index
|
59
|
-
cmd_class.action.must_equal :index
|
57
|
+
_(cmd.action).must_equal :index
|
58
|
+
_(cmd_class.action).must_equal :index
|
60
59
|
end
|
61
60
|
|
62
61
|
it "should set resource alone" do
|
63
62
|
cmd_class.resource :architectures
|
64
63
|
|
65
|
-
cmd.resource.name.must_equal :architectures
|
66
|
-
cmd_class.resource.name.must_equal :architectures
|
64
|
+
_(cmd.resource.name).must_equal :architectures
|
65
|
+
_(cmd_class.resource.name).must_equal :architectures
|
67
66
|
|
68
|
-
cmd.action
|
69
|
-
cmd_class.action
|
67
|
+
assert_nil cmd.action
|
68
|
+
assert_nil cmd_class.action
|
70
69
|
end
|
71
70
|
|
72
71
|
it "should set resource and action alone" do
|
73
72
|
cmd_class.resource :architectures
|
74
73
|
cmd_class.action :index
|
75
74
|
|
76
|
-
cmd.resource.name.must_equal :architectures
|
77
|
-
cmd_class.resource.name.must_equal :architectures
|
75
|
+
_(cmd.resource.name).must_equal :architectures
|
76
|
+
_(cmd_class.resource.name).must_equal :architectures
|
78
77
|
|
79
|
-
cmd.action.must_equal :index
|
80
|
-
cmd_class.action.must_equal :index
|
78
|
+
_(cmd.action).must_equal :index
|
79
|
+
_(cmd_class.action).must_equal :index
|
81
80
|
end
|
82
81
|
|
83
82
|
it "inherits action from a parent class" do
|
84
83
|
cmd_b = CommandA::CommandB.new("", ctx)
|
85
|
-
cmd_b.action.must_equal :show
|
86
|
-
cmd_b.class.action.must_equal :show
|
84
|
+
_(cmd_b.action).must_equal :show
|
85
|
+
_(cmd_b.class.action).must_equal :show
|
87
86
|
end
|
88
87
|
|
89
88
|
it "looks up resource in the class' modules" do
|
90
89
|
cmd_b = CommandA::CommandB.new("", ctx)
|
91
|
-
cmd_b.resource.name.must_equal :architectures
|
92
|
-
cmd_b.class.resource.name.must_equal :architectures
|
90
|
+
_(cmd_b.resource.name).must_equal :architectures
|
91
|
+
_(cmd_b.class.resource.name).must_equal :architectures
|
93
92
|
end
|
94
93
|
|
95
94
|
it "looks up resource in the superclass" do
|
96
95
|
cmd_c = CommandC.new("", ctx)
|
97
|
-
cmd_c.resource.name.must_equal :architectures
|
98
|
-
cmd_c.class.resource.name.must_equal :architectures
|
96
|
+
_(cmd_c.resource.name).must_equal :architectures
|
97
|
+
_(cmd_c.class.resource.name).must_equal :architectures
|
99
98
|
end
|
100
99
|
end
|
101
100
|
|
102
101
|
it "should raise exception when no action is defined" do
|
103
102
|
cmd.stubs(:handle_exception).returns(HammerCLI::EX_SOFTWARE)
|
104
|
-
cmd_run.must_equal HammerCLI::EX_SOFTWARE
|
103
|
+
_(cmd_run).must_equal HammerCLI::EX_SOFTWARE
|
105
104
|
end
|
106
105
|
|
107
106
|
context "resource defined" do
|
108
107
|
it "should perform a call to api when resource is defined" do
|
109
108
|
ApipieBindings::API.any_instance.expects(:call).returns([])
|
110
109
|
cmd.class.resource :architectures, :index
|
111
|
-
cmd_run.must_equal 0
|
110
|
+
_(cmd_run).must_equal 0
|
112
111
|
end
|
113
112
|
end
|
114
113
|
|
@@ -117,13 +116,13 @@ describe HammerCLI::Apipie::Command do
|
|
117
116
|
it "should collect method options from given options" do
|
118
117
|
cmd_opt = OptionCommand.new("", ctx)
|
119
118
|
params = cmd_opt.class.resource.action(:create).params
|
120
|
-
cmd_opt.method_options_for_params(params, {'option_name' => 'name'}).must_equal({"architecture" => {"name" => "name"}})
|
119
|
+
_(cmd_opt.method_options_for_params(params, {'option_name' => 'name'})).must_equal({"architecture" => {"name" => "name"}})
|
121
120
|
end
|
122
121
|
|
123
122
|
it "should collect method options from methods" do
|
124
123
|
cmd_opt = OptionCommand.new("", ctx)
|
125
124
|
params = cmd_opt.class.resource.action(:create).params
|
126
|
-
cmd_opt.method_options_for_params(params, {}).must_equal({"architecture"=>{"name"=>"test_name"}})
|
125
|
+
_(cmd_opt.method_options_for_params(params, {})).must_equal({"architecture"=>{"name"=>"test_name"}})
|
127
126
|
end
|
128
127
|
|
129
128
|
end
|
@@ -148,7 +147,7 @@ describe HammerCLI::Apipie::Command do
|
|
148
147
|
''
|
149
148
|
].join("\n")
|
150
149
|
expected_result = success_result(expected_messages)
|
151
|
-
result = run_cmd([], { :verbosity => HammerCLI::V_QUIET }, MessagesCommand)
|
150
|
+
result = run_cmd([], { :verbosity => HammerCLI::V_QUIET }, Class.new(MessagesCommand))
|
152
151
|
assert_cmd(expected_result, result)
|
153
152
|
end
|
154
153
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '
|
1
|
+
require File.join(File.dirname(__FILE__), './test_helper')
|
2
2
|
|
3
3
|
|
4
4
|
describe HammerCLI::OptionBuilderContainer do
|
@@ -23,27 +23,27 @@ describe HammerCLI::Apipie::OptionBuilder do
|
|
23
23
|
context "with one simple param" do
|
24
24
|
|
25
25
|
it "should create an option for the parameter" do
|
26
|
-
options.length.must_equal 1
|
26
|
+
_(options.length).must_equal 1
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should set correct switch" do
|
30
|
-
options[0].switches.must_be :include?, '--se-arch-val-ue'
|
30
|
+
_(options[0].switches).must_be :include?, '--se-arch-val-ue'
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should set correct attribute name" do
|
34
|
-
options[0].attribute_name.must_equal HammerCLI.option_accessor_name('se_arch_val_ue')
|
34
|
+
_(options[0].attribute_name).must_equal HammerCLI.option_accessor_name('se_arch_val_ue')
|
35
35
|
end
|
36
36
|
|
37
37
|
it "should set description with html tags stripped" do
|
38
|
-
options[0].description.must_equal 'filter results'
|
38
|
+
_(options[0].description).must_equal 'filter results'
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should build option with default family" do
|
42
|
-
options[0].family.wont_be_nil
|
42
|
+
_(options[0].family).wont_be_nil
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should build parent option within default family" do
|
46
|
-
options[0].child
|
46
|
+
_(options[0].child?).must_equal false
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -54,12 +54,12 @@ describe HammerCLI::Apipie::OptionBuilder do
|
|
54
54
|
let(:required_options) { builder.build(builder_options).reject{|opt| !opt.required?} }
|
55
55
|
|
56
56
|
it "should set required flag for the required options" do
|
57
|
-
required_options.map(&:attribute_name).sort.must_equal [HammerCLI.option_accessor_name("array_param")]
|
57
|
+
_(required_options.map(&:attribute_name).sort).must_equal [HammerCLI.option_accessor_name("array_param")]
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should not require any option when requirements are disabled" do
|
61
61
|
builder.require_options = false
|
62
|
-
required_options.map(&:attribute_name).sort.must_equal []
|
62
|
+
_(required_options.map(&:attribute_name).sort).must_equal []
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
@@ -68,11 +68,11 @@ describe HammerCLI::Apipie::OptionBuilder do
|
|
68
68
|
let(:action) {resource.action(:create)}
|
69
69
|
|
70
70
|
it "should create options for all parameters except the hash" do
|
71
|
-
options.map(&:attribute_name).sort.must_equal HammerCLI.option_accessor_name("array_param", "name", "provider")
|
71
|
+
_(options.map(&:attribute_name).sort).must_equal HammerCLI.option_accessor_name("array_param", "name", "provider")
|
72
72
|
end
|
73
73
|
|
74
74
|
it "should name the options correctly" do
|
75
|
-
options.map(&:attribute_name).sort.must_equal HammerCLI.option_accessor_name("array_param", "name", "provider")
|
75
|
+
_(options.map(&:attribute_name).sort).must_equal HammerCLI.option_accessor_name("array_param", "name", "provider")
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
@@ -81,39 +81,39 @@ describe HammerCLI::Apipie::OptionBuilder do
|
|
81
81
|
|
82
82
|
it "should set array normalizer" do
|
83
83
|
array_option = options.find {|o| o.attribute_name == HammerCLI.option_accessor_name("array_param") }
|
84
|
-
array_option.value_formatter.class.must_equal HammerCLI::Options::Normalizers::List
|
84
|
+
_(array_option.value_formatter.class).must_equal HammerCLI::Options::Normalizers::List
|
85
85
|
end
|
86
86
|
|
87
87
|
it "should set boolean normalizer" do
|
88
88
|
boolean_option = options.find {|o| o.attribute_name == HammerCLI.option_accessor_name("boolean_param") }
|
89
|
-
boolean_option.value_formatter.class.must_equal HammerCLI::Options::Normalizers::Bool
|
89
|
+
_(boolean_option.value_formatter.class).must_equal HammerCLI::Options::Normalizers::Bool
|
90
90
|
end
|
91
91
|
|
92
92
|
it "should set enum normalizer" do
|
93
93
|
enum_option = options.find {|o| o.attribute_name == HammerCLI.option_accessor_name("enum_param") }
|
94
|
-
enum_option.value_formatter.class.must_equal HammerCLI::Options::Normalizers::Enum
|
95
|
-
enum_option.value_formatter.allowed_values.sort.must_equal ["one", "two", "three"].sort
|
94
|
+
_(enum_option.value_formatter.class).must_equal HammerCLI::Options::Normalizers::Enum
|
95
|
+
_(enum_option.value_formatter.allowed_values.sort).must_equal ["one", "two", "three"].sort
|
96
96
|
end
|
97
97
|
|
98
98
|
it "should set enum normalizer and handle coded values" do
|
99
99
|
enum_option = options.find {|o| o.attribute_name == HammerCLI.option_accessor_name("coded_enum_param") }
|
100
|
-
enum_option.value_formatter.class.must_equal HammerCLI::Options::Normalizers::Enum
|
101
|
-
enum_option.value_formatter.allowed_values.sort.must_equal ["array", "boolean", "hash", "integer", "json", "real", "string", "yaml"].sort
|
100
|
+
_(enum_option.value_formatter.class).must_equal HammerCLI::Options::Normalizers::Enum
|
101
|
+
_(enum_option.value_formatter.allowed_values.sort).must_equal ["array", "boolean", "hash", "integer", "json", "real", "string", "yaml"].sort
|
102
102
|
end
|
103
103
|
|
104
104
|
it "should set list normalizer for array of nested elements" do
|
105
105
|
array_option = options.find {|o| o.attribute_name == HammerCLI.option_accessor_name("nested_elements_param") }
|
106
|
-
array_option.value_formatter.class.must_equal HammerCLI::Options::Normalizers::List
|
106
|
+
_(array_option.value_formatter.class).must_equal HammerCLI::Options::Normalizers::List
|
107
107
|
end
|
108
108
|
|
109
109
|
it "should set number normalizer" do
|
110
110
|
numeric_option = options.find {|o| o.attribute_name == HammerCLI.option_accessor_name("numeric_param") }
|
111
|
-
numeric_option.value_formatter.class.must_equal HammerCLI::Options::Normalizers::Number
|
111
|
+
_(numeric_option.value_formatter.class).must_equal HammerCLI::Options::Normalizers::Number
|
112
112
|
end
|
113
113
|
|
114
114
|
it "should set number normalizer for integer" do
|
115
115
|
integer_option = options.find {|o| o.attribute_name == HammerCLI.option_accessor_name("integer_param") }
|
116
|
-
integer_option.value_formatter.class.must_equal HammerCLI::Options::Normalizers::Number
|
116
|
+
_(integer_option.value_formatter.class).must_equal HammerCLI::Options::Normalizers::Number
|
117
117
|
end
|
118
118
|
|
119
119
|
end
|
@@ -124,22 +124,22 @@ describe HammerCLI::Apipie::OptionBuilder do
|
|
124
124
|
|
125
125
|
it "should skip filtered options" do
|
126
126
|
builder_options[:without] = ["provider", "name"]
|
127
|
-
options.map(&:attribute_name).sort.must_equal [HammerCLI.option_accessor_name("array_param")]
|
127
|
+
_(options.map(&:attribute_name).sort).must_equal [HammerCLI.option_accessor_name("array_param")]
|
128
128
|
end
|
129
129
|
|
130
130
|
it "should skip filtered options defined as symbols" do
|
131
131
|
builder_options[:without] = [:provider, :name]
|
132
|
-
options.map(&:attribute_name).sort.must_equal [HammerCLI.option_accessor_name("array_param")]
|
132
|
+
_(options.map(&:attribute_name).sort).must_equal [HammerCLI.option_accessor_name("array_param")]
|
133
133
|
end
|
134
134
|
|
135
135
|
it "should skip single filtered option in array" do
|
136
136
|
builder_options[:without] = ["provider"]
|
137
|
-
options.map(&:attribute_name).sort.must_equal HammerCLI.option_accessor_name("array_param", "name")
|
137
|
+
_(options.map(&:attribute_name).sort).must_equal HammerCLI.option_accessor_name("array_param", "name")
|
138
138
|
end
|
139
139
|
|
140
140
|
it "should skip single filtered option" do
|
141
141
|
builder_options[:without] = "provider"
|
142
|
-
options.map(&:attribute_name).sort.must_equal HammerCLI.option_accessor_name("array_param", "name")
|
142
|
+
_(options.map(&:attribute_name).sort).must_equal HammerCLI.option_accessor_name("array_param", "name")
|
143
143
|
end
|
144
144
|
|
145
145
|
end
|
@@ -155,17 +155,17 @@ describe HammerCLI::Apipie::OptionBuilder do
|
|
155
155
|
|
156
156
|
it "renames options" do
|
157
157
|
# builder_options[:resource_mapping] = {:organization => 'company', 'compute_resource' => :compute_provider}
|
158
|
-
options.map(&:long_switch).sort.must_equal ["--company-id", "--company-ids", "--compute-provider-id", "--name"]
|
158
|
+
_(options.map(&:long_switch).sort).must_equal ["--company-id", "--company-ids", "--compute-provider-id", "--name"]
|
159
159
|
end
|
160
160
|
|
161
161
|
it "renames option types" do
|
162
162
|
# builder_options[:resource_mapping] = {:organization => 'company', 'compute_resource' => :compute_provider}
|
163
|
-
options.map(&:type).sort.must_equal ["COMPANY_ID", "COMPANY_IDS", "COMPUTE_PROVIDER_ID", "NAME"]
|
163
|
+
_(options.map(&:type).sort).must_equal ["COMPANY_ID", "COMPANY_IDS", "COMPUTE_PROVIDER_ID", "NAME"]
|
164
164
|
end
|
165
165
|
|
166
166
|
it "keeps option accessor the same" do
|
167
167
|
# builder_options[:resource_mapping] = {:organization => 'company', 'compute_resource' => :compute_provider}
|
168
|
-
options.map(&:attribute_name).sort.must_equal HammerCLI.option_accessor_name("compute_resource_id", "name", "organization_id", "organization_ids")
|
168
|
+
_(options.map(&:attribute_name).sort).must_equal HammerCLI.option_accessor_name("compute_resource_id", "name", "organization_id", "organization_ids")
|
169
169
|
end
|
170
170
|
|
171
171
|
end
|
@@ -174,7 +174,7 @@ describe HammerCLI::Apipie::OptionBuilder do
|
|
174
174
|
let(:action) {resource.action(:action_with_ids)}
|
175
175
|
|
176
176
|
it "sets referenced resources" do
|
177
|
-
options.map(&:referenced_resource).map(&:to_s).sort.must_equal ["", "compute_resource", "organization", "organization"]
|
177
|
+
_(options.map(&:referenced_resource).map(&:to_s).sort).must_equal ["", "compute_resource", "organization", "organization"]
|
178
178
|
end
|
179
179
|
end
|
180
180
|
|