hammer_cli 0.15.1 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/doc/commands_modification.md +82 -0
  3. data/doc/creating_commands.md +78 -38
  4. data/doc/developer_docs.md +2 -0
  5. data/doc/help_modification.md +119 -0
  6. data/doc/i18n.md +2 -2
  7. data/doc/installation_rpm.md +3 -3
  8. data/doc/release_notes.md +9 -1
  9. data/lib/hammer_cli.rb +0 -1
  10. data/lib/hammer_cli/abstract.rb +44 -13
  11. data/lib/hammer_cli/exception_handler.rb +1 -1
  12. data/lib/hammer_cli/help/definition.rb +55 -0
  13. data/lib/hammer_cli/help/definition/abstract_item.rb +38 -0
  14. data/lib/hammer_cli/help/definition/list.rb +53 -0
  15. data/lib/hammer_cli/help/definition/section.rb +36 -0
  16. data/lib/hammer_cli/help/definition/text.rb +21 -0
  17. data/lib/hammer_cli/help/text_builder.rb +26 -49
  18. data/lib/hammer_cli/i18n.rb +0 -1
  19. data/lib/hammer_cli/options/option_collector.rb +12 -9
  20. data/lib/hammer_cli/options/option_processor.rb +17 -0
  21. data/lib/hammer_cli/options/processor_list.rb +37 -0
  22. data/lib/hammer_cli/options/sources/base.rb +17 -0
  23. data/lib/hammer_cli/options/sources/command_line.rb +3 -1
  24. data/lib/hammer_cli/options/sources/saved_defaults.rb +3 -1
  25. data/lib/hammer_cli/options/validators/base.rb +20 -0
  26. data/lib/hammer_cli/options/validators/dsl.rb +160 -0
  27. data/lib/hammer_cli/options/validators/dsl_block_validator.rb +19 -0
  28. data/lib/hammer_cli/output/adapter/csv.rb +11 -11
  29. data/lib/hammer_cli/output/adapter/tree_structure.rb +5 -3
  30. data/lib/hammer_cli/output/definition.rb +42 -4
  31. data/lib/hammer_cli/output/dsl.rb +4 -2
  32. data/lib/hammer_cli/output/fields.rb +9 -2
  33. data/lib/hammer_cli/testing/messages.rb +6 -6
  34. data/lib/hammer_cli/utils.rb +15 -0
  35. data/lib/hammer_cli/version.rb +1 -1
  36. data/locale/ca/LC_MESSAGES/hammer-cli.mo +0 -0
  37. data/locale/de/LC_MESSAGES/hammer-cli.mo +0 -0
  38. data/locale/en/LC_MESSAGES/hammer-cli.mo +0 -0
  39. data/locale/en_GB/LC_MESSAGES/hammer-cli.mo +0 -0
  40. data/locale/es/LC_MESSAGES/hammer-cli.mo +0 -0
  41. data/locale/fr/LC_MESSAGES/hammer-cli.mo +0 -0
  42. data/locale/it/LC_MESSAGES/hammer-cli.mo +0 -0
  43. data/locale/ja/LC_MESSAGES/hammer-cli.mo +0 -0
  44. data/locale/ko/LC_MESSAGES/hammer-cli.mo +0 -0
  45. data/locale/pt_BR/LC_MESSAGES/hammer-cli.mo +0 -0
  46. data/locale/ru/LC_MESSAGES/hammer-cli.mo +0 -0
  47. data/locale/zh_CN/LC_MESSAGES/hammer-cli.mo +0 -0
  48. data/locale/zh_TW/LC_MESSAGES/hammer-cli.mo +0 -0
  49. data/test/unit/abstract_test.rb +70 -5
  50. data/test/unit/exception_handler_test.rb +1 -1
  51. data/test/unit/help/definition/abstract_item_test.rb +33 -0
  52. data/test/unit/help/definition/list_test.rb +17 -0
  53. data/test/unit/help/definition/section_test.rb +25 -0
  54. data/test/unit/help/definition/text_test.rb +11 -0
  55. data/test/unit/help/definition_test.rb +236 -0
  56. data/test/unit/help/text_builder_test.rb +170 -1
  57. data/test/unit/options/option_collector_test.rb +18 -9
  58. data/test/unit/options/processor_list_test.rb +70 -0
  59. data/test/unit/{validator_test.rb → options/validators/dsl_test.rb} +57 -93
  60. data/test/unit/output/adapter/abstract_test.rb +3 -0
  61. data/test/unit/output/adapter/base_test.rb +5 -0
  62. data/test/unit/output/adapter/csv_test.rb +3 -0
  63. data/test/unit/output/adapter/json_test.rb +12 -0
  64. data/test/unit/output/adapter/table_test.rb +5 -0
  65. data/test/unit/output/adapter/yaml_test.rb +11 -0
  66. data/test/unit/output/definition_test.rb +221 -1
  67. data/test/unit/utils_test.rb +23 -0
  68. metadata +31 -5
  69. data/lib/hammer_cli/validator.rb +0 -172
@@ -241,6 +241,11 @@ describe HammerCLI::Output::Adapter::Base do
241
241
 
242
242
  end
243
243
 
244
+ context 'print_message' do
245
+ it 'should print message with nil params' do
246
+ proc { adapter.print_message('MESSAGE', nil) }.must_output(/.*MESSAGE.*/, '')
247
+ end
248
+ end
244
249
  end
245
250
 
246
251
  end
@@ -257,6 +257,9 @@ describe HammerCLI::Output::Adapter::CSValues do
257
257
  }.must_output("Message,Id,Name\nSOME MESSAGE,83,new_record\n", "")
258
258
  end
259
259
 
260
+ it 'should print message with nil params' do
261
+ proc { adapter.print_message('MESSAGE', nil) }.must_output("Message\nMESSAGE\n", '')
262
+ end
260
263
  end
261
264
 
262
265
  end
@@ -37,6 +37,18 @@ describe HammerCLI::Output::Adapter::Json do
37
37
 
38
38
  proc { adapter.print_message(msg, params) }.must_output(expected_output)
39
39
  end
40
+
41
+ it 'prints the message with nil params' do
42
+ params = nil
43
+ msg = 'MESSAGE'
44
+ expected_output = [
45
+ '{',
46
+ ' "message": "MESSAGE"',
47
+ '}',
48
+ ''
49
+ ].join("\n")
50
+ proc { adapter.print_message(msg, params) }.must_output(expected_output)
51
+ end
40
52
  end
41
53
 
42
54
  context "print_collection" do
@@ -410,6 +410,11 @@ describe HammerCLI::Output::Adapter::Table do
410
410
 
411
411
  end
412
412
 
413
+ context 'print_message' do
414
+ it 'should print message with nil params' do
415
+ proc { adapter.print_message('MESSAGE', nil) }.must_output(/.*MESSAGE.*/, '')
416
+ end
417
+ end
413
418
  end
414
419
 
415
420
  end
@@ -35,6 +35,17 @@ describe HammerCLI::Output::Adapter::Yaml do
35
35
 
36
36
  proc { adapter.print_message(msg, params) }.must_output(expected_output)
37
37
  end
38
+
39
+ it 'prints the message with nil params' do
40
+ params = nil
41
+ msg = 'MESSAGE'
42
+ expected_output = [
43
+ '---',
44
+ ':message: MESSAGE',
45
+ ''
46
+ ].join("\n")
47
+ proc { adapter.print_message(msg, params) }.must_output(expected_output)
48
+ end
38
49
  end
39
50
 
40
51
  context "print_collection" do
@@ -7,6 +7,10 @@ describe HammerCLI::Output::Definition do
7
7
  let(:definition) { HammerCLI::Output::Definition.new }
8
8
  let(:last_field) { definition.fields[-1] }
9
9
  let(:field_count) { definition.fields.length }
10
+ let(:new_field) { Fields::Field.new(label: 'newfield', id: :new_id) }
11
+ let(:label_field) { Fields::Label.new(label: 'labelfield') }
12
+ let(:cont_field) { Fields::ContainerField.new(id: :id1) }
13
+
10
14
 
11
15
  describe "empty?" do
12
16
 
@@ -36,5 +40,221 @@ describe HammerCLI::Output::Definition do
36
40
  definition.fields.must_equal another_def.fields
37
41
  end
38
42
 
39
- end
43
+ it 'clear should delete all fields' do
44
+ definition.fields << Fields::Field.new
45
+ definition.clear
46
+ definition.empty?.must_equal true
47
+ end
48
+
49
+ describe 'insert' do
50
+ let(:new_fields) { [new_field, new_field] }
51
+
52
+ describe 'before' do
53
+ it 'should not insert field if output definition is empty' do
54
+ definition.clear
55
+ assert_raises ArgumentError do
56
+ definition.insert(:before, :id1, new_field)
57
+ end
58
+
59
+ field_count.must_equal 0
60
+ end
61
+
62
+ it 'should insert new specified field before the old one' do
63
+ definition.fields << Fields::Field.new(id: :id1, label: 'oldfield')
64
+ definition.insert(:before, :id1, new_field)
65
+
66
+ definition.fields.first.label.must_equal new_field.label
67
+ field_count.must_equal 2
68
+ end
69
+
70
+ it 'should insert before field with few new specified' do
71
+ definition.fields << Fields::Field.new(id: :id1, label: 'oldfield')
72
+ definition.insert(:before, :id1, new_fields)
73
+
74
+ definition.fields.first.label.must_equal new_field.label
75
+ field_count.must_equal 3
76
+ end
77
+
78
+ it 'should accept block with new fields' do
79
+ definition.fields << Fields::Field.new(id: :id1, label: 'oldfield')
80
+ definition.insert(:before, :id1) do
81
+ field nil, 'newfield'
82
+ field nil, 'newfield2'
83
+ end
84
+
85
+ definition.fields.first.label.must_equal new_field.label
86
+ field_count.must_equal 3
87
+ end
88
+
89
+ it 'should accept both block and new fields' do
90
+ definition.fields << Fields::Field.new(id: :id1, label: 'oldfield')
91
+ definition.insert(:before, :id1, new_fields) do
92
+ field nil, 'newfield3'
93
+ field nil, 'newfield4'
94
+ end
95
+
96
+ definition.fields.first.label.must_equal new_field.label
97
+ field_count.must_equal 5
98
+ end
40
99
 
100
+ it 'should work with labels' do
101
+ label_field.output_definition.fields << new_field
102
+ definition.fields << label_field
103
+ definition.insert(:before, label_field.label, new_fields)
104
+
105
+ definition.fields.first.label.must_equal new_field.label
106
+ field_count.must_equal 3
107
+ end
108
+ end
109
+
110
+ describe 'after' do
111
+ it 'should not insert field if output definition is empty' do
112
+ definition.clear
113
+ assert_raises ArgumentError do
114
+ definition.insert(:after, :id1, new_field)
115
+ end
116
+
117
+ field_count.must_equal 0
118
+ end
119
+
120
+ it 'should insert new specified field after the old one' do
121
+ definition.fields << Fields::Field.new(id: :id1, label: 'oldfield')
122
+ definition.insert(:after, :id1, new_field)
123
+
124
+ definition.fields.first.label.must_equal 'oldfield'
125
+ field_count.must_equal 2
126
+ end
127
+
128
+ it 'should insert after field with few new specified' do
129
+ definition.fields << Fields::Field.new(id: :id1, label: 'oldfield')
130
+ definition.insert(:after, :id1, new_fields)
131
+
132
+ definition.fields.first.label.must_equal 'oldfield'
133
+ field_count.must_equal 3
134
+ end
135
+
136
+ it 'should accept block with new fields' do
137
+ definition.fields << Fields::Field.new(id: :id1, label: 'oldfield')
138
+ definition.insert(:after, :id1) do
139
+ field nil, 'newfield'
140
+ field nil, 'newfield2'
141
+ end
142
+
143
+ definition.fields.first.label.must_equal 'oldfield'
144
+ field_count.must_equal 3
145
+ end
146
+
147
+ it 'should accept both block and new fields' do
148
+ definition.fields << Fields::Field.new(id: :id1, label: 'oldfield')
149
+ definition.insert(:after, :id1, new_fields) do
150
+ field nil, 'newfield3'
151
+ field nil, 'newfield4'
152
+ end
153
+
154
+ definition.fields.first.label.must_equal 'oldfield'
155
+ field_count.must_equal 5
156
+ end
157
+
158
+ it 'should work with labels' do
159
+ label_field.output_definition.fields << new_field
160
+ definition.fields << label_field
161
+ definition.insert(:after, label_field.label, new_fields)
162
+
163
+ definition.fields.first.label.must_equal label_field.label
164
+ field_count.must_equal 3
165
+ end
166
+ end
167
+
168
+ describe 'replace' do
169
+ it 'should not replace field if output definition is empty' do
170
+ definition.clear
171
+ assert_raises ArgumentError do
172
+ definition.insert(:replace, :id1, new_field)
173
+ end
174
+
175
+ field_count.must_equal 0
176
+ end
177
+
178
+ it 'should replace field with new specified' do
179
+ definition.fields << Fields::Field.new(id: :id1, label: 'oldfield')
180
+ definition.insert(:replace, :id1, new_field)
181
+
182
+ definition.fields.first.label.must_equal new_field.label
183
+ field_count.must_equal 1
184
+ end
185
+
186
+ it 'should replace field with few new specified' do
187
+ definition.fields << Fields::Field.new(id: :id1, label: 'oldfield')
188
+ definition.insert(:replace, :id1, new_fields)
189
+
190
+ definition.fields.first.label.must_equal new_field.label
191
+ field_count.must_equal 2
192
+ end
193
+
194
+ it 'should accept block with new fields' do
195
+ definition.fields << Fields::Field.new(id: :id1, label: 'oldfield')
196
+ definition.insert(:replace, :id1) do
197
+ field nil, 'newfield'
198
+ field nil, 'newfield2'
199
+ end
200
+
201
+ definition.fields.first.label.must_equal new_field.label
202
+ end
203
+
204
+ it 'should accept both block and new fields' do
205
+ definition.fields << Fields::Field.new(id: :id1, label: 'oldfield')
206
+ definition.insert(:replace, :id1, new_fields) do
207
+ field nil, 'newfield3'
208
+ field nil, 'newfield4'
209
+ end
210
+
211
+ field_count.must_equal 4
212
+ end
213
+
214
+ it 'should work with labels' do
215
+ label_field.output_definition.fields << new_field
216
+ definition.fields << label_field
217
+ definition.insert(:replace, label_field.label, new_fields)
218
+
219
+ field_count.must_equal 2
220
+ end
221
+ end
222
+ end
223
+
224
+ describe 'find_field' do
225
+ it 'should find a field' do
226
+ definition.fields += [new_field, label_field]
227
+ definition.find_field(:new_id).must_equal new_field
228
+ end
229
+
230
+ it 'should find a field in field output definition' do
231
+ definition.fields += [label_field, cont_field]
232
+ nested_definition = definition.find_field(:id1).output_definition
233
+ nested_definition.fields << new_field
234
+ nested_definition.find_field(:new_id).must_equal new_field
235
+ end
236
+ end
237
+
238
+ describe 'at' do
239
+ it 'should return self if no specified path or empty' do
240
+ definition.at.must_equal definition
241
+ definition.at([]).must_equal definition
242
+ end
243
+
244
+ it 'should return output definition of specified field with path' do
245
+ cont_field.output_definition.fields << new_field
246
+ definition.fields << cont_field
247
+ path = [cont_field.id]
248
+
249
+ definition.at(path).must_equal cont_field.output_definition
250
+ end
251
+
252
+ it 'should work with labels' do
253
+ label_field.output_definition.fields << new_field
254
+ definition.fields << label_field
255
+ path = ['labelfield']
256
+
257
+ definition.at(path).must_equal label_field.output_definition
258
+ end
259
+ end
260
+ end
@@ -169,4 +169,27 @@ describe HammerCLI do
169
169
  end
170
170
  end
171
171
 
172
+ describe 'insert_relative' do
173
+ let(:arr) { [:a, :b, :c] }
174
+
175
+ it 'appends' do
176
+ HammerCLI.insert_relative(arr, :append, nil, 1, 2, 3)
177
+ assert_equal(arr, [:a, :b, :c, 1, 2, 3])
178
+ end
179
+
180
+ it 'prepends' do
181
+ HammerCLI.insert_relative(arr, :prepend, nil, 1, 2, 3)
182
+ assert_equal(arr, [1, 2, 3, :a, :b, :c])
183
+ end
184
+
185
+ it 'inserts after index' do
186
+ HammerCLI.insert_relative(arr, :after, 1, 1, 2, 3)
187
+ assert_equal(arr, [:a, :b, 1, 2, 3, :c])
188
+ end
189
+
190
+ it 'inserts before index' do
191
+ HammerCLI.insert_relative(arr, :before, 1, 1, 2, 3)
192
+ assert_equal(arr, [:a, 1, 2, 3, :b, :c])
193
+ end
194
+ end
172
195
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hammer_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.1
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Bačovský
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-11-06 00:00:00.000000000 Z
12
+ date: 2019-01-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: clamp
@@ -154,6 +154,7 @@ extra_rdoc_files:
154
154
  - doc/design.png
155
155
  - doc/option_normalizers.md
156
156
  - doc/release_notes.md
157
+ - doc/commands_modification.md
157
158
  - doc/creating_commands.md
158
159
  - doc/development_tips.md
159
160
  - doc/developer_docs.md
@@ -162,6 +163,7 @@ extra_rdoc_files:
162
163
  - doc/installation_rpm.md
163
164
  - doc/i18n.md
164
165
  - doc/installation.md
166
+ - doc/help_modification.md
165
167
  - doc/installation_source.md
166
168
  - doc/design.uml
167
169
  - doc/installation_gem.md
@@ -176,12 +178,14 @@ files:
176
178
  - bin/hammer
177
179
  - config/cli.modules.d/module_config_template.yml
178
180
  - config/cli_config.template.yml
181
+ - doc/commands_modification.md
179
182
  - doc/creating_apipie_commands.md
180
183
  - doc/creating_commands.md
181
184
  - doc/design.png
182
185
  - doc/design.uml
183
186
  - doc/developer_docs.md
184
187
  - doc/development_tips.md
188
+ - doc/help_modification.md
185
189
  - doc/i18n.md
186
190
  - doc/installation.md
187
191
  - doc/installation_deb.md
@@ -216,6 +220,11 @@ files:
216
220
  - lib/hammer_cli/exit_codes.rb
217
221
  - lib/hammer_cli/full_help.rb
218
222
  - lib/hammer_cli/help/builder.rb
223
+ - lib/hammer_cli/help/definition.rb
224
+ - lib/hammer_cli/help/definition/abstract_item.rb
225
+ - lib/hammer_cli/help/definition/list.rb
226
+ - lib/hammer_cli/help/definition/section.rb
227
+ - lib/hammer_cli/help/definition/text.rb
219
228
  - lib/hammer_cli/help/text_builder.rb
220
229
  - lib/hammer_cli/i18n.rb
221
230
  - lib/hammer_cli/i18n/find_task.rb
@@ -229,8 +238,14 @@ files:
229
238
  - lib/hammer_cli/options/normalizers.rb
230
239
  - lib/hammer_cli/options/option_collector.rb
231
240
  - lib/hammer_cli/options/option_definition.rb
241
+ - lib/hammer_cli/options/option_processor.rb
242
+ - lib/hammer_cli/options/processor_list.rb
243
+ - lib/hammer_cli/options/sources/base.rb
232
244
  - lib/hammer_cli/options/sources/command_line.rb
233
245
  - lib/hammer_cli/options/sources/saved_defaults.rb
246
+ - lib/hammer_cli/options/validators/base.rb
247
+ - lib/hammer_cli/options/validators/dsl.rb
248
+ - lib/hammer_cli/options/validators/dsl_block_validator.rb
234
249
  - lib/hammer_cli/output.rb
235
250
  - lib/hammer_cli/output/adapter.rb
236
251
  - lib/hammer_cli/output/adapter/abstract.rb
@@ -259,7 +274,6 @@ files:
259
274
  - lib/hammer_cli/testing/messages.rb
260
275
  - lib/hammer_cli/testing/output_matchers.rb
261
276
  - lib/hammer_cli/utils.rb
262
- - lib/hammer_cli/validator.rb
263
277
  - lib/hammer_cli/verbosity.rb
264
278
  - lib/hammer_cli/version.rb
265
279
  - locale/ca/LC_MESSAGES/hammer-cli.mo
@@ -439,6 +453,11 @@ files:
439
453
  - test/unit/fixtures/json_input/invalid.json
440
454
  - test/unit/fixtures/json_input/valid.json
441
455
  - test/unit/help/builder_test.rb
456
+ - test/unit/help/definition/abstract_item_test.rb
457
+ - test/unit/help/definition/list_test.rb
458
+ - test/unit/help/definition/section_test.rb
459
+ - test/unit/help/definition/text_test.rb
460
+ - test/unit/help/definition_test.rb
442
461
  - test/unit/help/text_builder_test.rb
443
462
  - test/unit/history_test.rb
444
463
  - test/unit/i18n_test.rb
@@ -451,8 +470,10 @@ files:
451
470
  - test/unit/options/normalizers_test.rb
452
471
  - test/unit/options/option_collector_test.rb
453
472
  - test/unit/options/option_definition_test.rb
473
+ - test/unit/options/processor_list_test.rb
454
474
  - test/unit/options/sources/command_line_test.rb
455
475
  - test/unit/options/sources/saved_defaults_test.rb
476
+ - test/unit/options/validators/dsl_test.rb
456
477
  - test/unit/output/adapter/abstract_test.rb
457
478
  - test/unit/output/adapter/base_test.rb
458
479
  - test/unit/output/adapter/csv_test.rb
@@ -469,7 +490,6 @@ files:
469
490
  - test/unit/settings_test.rb
470
491
  - test/unit/test_helper.rb
471
492
  - test/unit/utils_test.rb
472
- - test/unit/validator_test.rb
473
493
  homepage: https://github.com/theforeman/hammer-cli
474
494
  licenses:
475
495
  - GPL-3.0
@@ -635,8 +655,13 @@ test_files:
635
655
  - test/unit/utils_test.rb
636
656
  - test/unit/settings_test.rb
637
657
  - test/unit/modules_test.rb
658
+ - test/unit/help/definition/abstract_item_test.rb
659
+ - test/unit/help/definition/list_test.rb
660
+ - test/unit/help/definition/text_test.rb
661
+ - test/unit/help/definition/section_test.rb
638
662
  - test/unit/help/builder_test.rb
639
663
  - test/unit/help/text_builder_test.rb
664
+ - test/unit/help/definition_test.rb
640
665
  - test/unit/abstract_test.rb
641
666
  - test/unit/i18n_test.rb
642
667
  - test/unit/logger_test.rb
@@ -664,12 +689,13 @@ test_files:
664
689
  - test/unit/apipie/command_test.rb
665
690
  - test/unit/apipie/option_builder_test.rb
666
691
  - test/unit/apipie/test_helper.rb
667
- - test/unit/validator_test.rb
668
692
  - test/unit/options/option_collector_test.rb
669
693
  - test/unit/options/sources/saved_defaults_test.rb
670
694
  - test/unit/options/sources/command_line_test.rb
671
695
  - test/unit/options/normalizers_test.rb
696
+ - test/unit/options/validators/dsl_test.rb
672
697
  - test/unit/options/option_definition_test.rb
698
+ - test/unit/options/processor_list_test.rb
673
699
  - test/unit/options/matcher_test.rb
674
700
  - test/unit/option_builder_test.rb
675
701
  - test/unit/fixtures/certs/non_ca_cert.pem