hammer_cli 2.5.0 → 2.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a632fb8b3ddc1914f0110af4371d152d31e0efe042453512c55dd1384b8bafc
4
- data.tar.gz: 76029ef771f18e0096ffdc18f897b1758d09c58277065dce55907f625f13d77e
3
+ metadata.gz: a39815aa1d748fda7475b583f55c801a8391e21a6418aad7e479a3a8754f1412
4
+ data.tar.gz: ffce03a8a4057f28dd21fde44100a7867f7efe2ce2f2f7e2a18dd0b037ce5983
5
5
  SHA512:
6
- metadata.gz: 6777ff43f35fb9b29332e3f02ed68320a5a0f526da5c1a0256f714223ceed72c6d09f3982d0df252be82e2e7ea754fd6105d202f68eebac030d9e6fc6a3db6b6
7
- data.tar.gz: 0e7ddb3ea2aaf2080ab8b796c9eb0f68d747a0d290a57bb84e53386de86e17cb51dfbf266fccce3bee71c38123ce0aa67773aaca963fa8001840a56a8a03d467
6
+ metadata.gz: fdfe7222cc2b1dc5059a62b8cdef4effd09af391d5880fb2f2315d9ca8d20124ffa2aa07aaebc56be6dd01cf988c69490b8a98da86e29fd166949d9d67e257c3
7
+ data.tar.gz: 34ee4d3731a3a4d4e883acb11dd7dcae4b7cdc9ff45cc513642ebef428a67fd33e7072cc37ba4a8d791c0425afbdfbc8506bc032041e0d86b62387f736aeb32e
@@ -16,11 +16,11 @@ Each command can be easily extended with one ore more `HammerCLI::CommandExtensi
16
16
  child option_params
17
17
  end
18
18
  # Extend hash with data returned from server before it is printed
19
- before_print do |data|
19
+ before_print do |data, command_object, command_class|
20
20
  # data modifications
21
21
  end
22
22
  # Extend command's output definition
23
- output do |definition|
23
+ output do |definition, command_object, command_class|
24
24
  # output definition modifications
25
25
  end
26
26
  # Extend command's help definition
@@ -28,19 +28,19 @@ Each command can be easily extended with one ore more `HammerCLI::CommandExtensi
28
28
  # help modifications
29
29
  end
30
30
  # Extend hash with headers before request is sent
31
- request_headers do |headers|
31
+ request_headers do |headers, command_object, command_class|
32
32
  # headers modifications
33
33
  end
34
34
  # Extend hash with options before request is sent
35
- request_options do |options|
35
+ request_options do |options, command_object, command_class|
36
36
  # options modifications
37
37
  end
38
38
  # Extend hash with params before request is sent
39
- request_params do |params|
39
+ request_params do |params, command_object, command_class|
40
40
  # params modifications
41
41
  end
42
42
  # Extend option sources
43
- option_sources do |sources, command|
43
+ option_sources do |sources, command_object, command_class|
44
44
  # no need to call super method
45
45
  # simply add your sources to sources variable
46
46
  end
@@ -63,6 +63,8 @@ __NOTE:__
63
63
  - `request_*` extensions are applied before sending a request to the server
64
64
  - `option`, `output`, `help` extensions are applied right away after the command is extended with `extend_with`
65
65
  - `before_print` extensions are applied right away after the server returns the data
66
+ - `request_*`, `output`, `before_print` extensions have access to the command object
67
+ after the command with the extension was initialized
66
68
 
67
69
  #### Example
68
70
  ```ruby
data/doc/release_notes.md CHANGED
@@ -1,5 +1,11 @@
1
1
  Release notes
2
2
  =============
3
+ ### 2.5.1 (2021-06-08)
4
+ * Add full comparison for fields option, [#31984](http://projects.theforeman.org/issues/31984)
5
+ * Force capitalized field names in help, [#32444](http://projects.theforeman.org/issues/32444)
6
+ * Unescape enum validator description, [#32570](http://projects.theforeman.org/issues/32570)
7
+ * Make cmd object be available in command extensions, [#32568](http://projects.theforeman.org/issues/32568)
8
+
3
9
  ### 2.5.0 (2021-05-04)
4
10
  * Better family assignment for options, [#30996](http://projects.theforeman.org/issues/30996)
5
11
  * Bump to 2.5.0-develop
@@ -20,6 +20,8 @@ module HammerCLI
20
20
  class AbstractCommand < Clamp::Command
21
21
  include HammerCLI::Subcommand
22
22
 
23
+ attr_reader :context
24
+
23
25
  class << self
24
26
  attr_accessor :validation_blocks
25
27
 
@@ -75,7 +77,7 @@ module HammerCLI
75
77
  begin
76
78
  begin
77
79
  exit_code = super
78
- context.delete(:fields)
80
+ clean_up_context
79
81
  raise "exit code must be integer" unless exit_code.is_a? Integer
80
82
  rescue => e
81
83
  exit_code = handle_exception(e)
@@ -97,6 +99,10 @@ module HammerCLI
97
99
  HammerCLI::EX_OK
98
100
  end
99
101
 
102
+ def clean_up_context
103
+ context.delete(:fields)
104
+ end
105
+
100
106
  def self.validate_options(mode=:append, target_name=nil, validator: nil, &block)
101
107
  validator ||= HammerCLI::Options::Validators::DSLBlockValidator.new(&block)
102
108
  self.validation_blocks ||= []
@@ -115,6 +121,9 @@ module HammerCLI
115
121
  super
116
122
  context[:path] ||= []
117
123
  context[:path] << self
124
+ self.class.command_extensions.each do |extension|
125
+ extension.command_object(self)
126
+ end
118
127
  end
119
128
 
120
129
  def parent_command
@@ -207,11 +216,12 @@ module HammerCLI
207
216
  raise ArgumentError, _('Command extensions should be inherited from %s.') % HammerCLI::CommandExtensions
208
217
  end
209
218
  extension.delegatee(self)
210
- extension.extend_predefined_options(self)
211
- extension.extend_options(self)
212
- extension.extend_option_family(self)
213
- extension.extend_output(self)
214
- extension.extend_help(self)
219
+ extension.command_class(self)
220
+ extension.extend_predefined_options
221
+ extension.extend_options
222
+ extension.extend_option_family
223
+ extension.extend_output
224
+ extension.extend_help
215
225
  logger('Extensions').info "Applied #{extension.details} on #{self}."
216
226
  command_extensions << extension
217
227
  end
@@ -359,7 +369,7 @@ module HammerCLI
359
369
 
360
370
  sources = HammerCLI::Options::ProcessorList.new([sources])
361
371
  self.class.command_extensions.each do |extension|
362
- extension.extend_option_sources(sources, self)
372
+ extension.extend_option_sources(sources)
363
373
  end
364
374
  sources
365
375
  end
@@ -72,7 +72,9 @@ module HammerCLI::Apipie
72
72
  elsif param.expected_type.to_s == 'boolean' || param.validator.to_s == 'boolean'
73
73
  opts[:format] = HammerCLI::Options::Normalizers::Bool.new
74
74
  elsif param.expected_type.to_s == 'string' && param.validator =~ /Must be one of: (.*)\./
75
- allowed = $1.split(/,\ ?/).map { |val| val.gsub(/<[^>]*>/i,'') }
75
+ allowed = $1.split(/,\ ?/).map { |val| val.gsub(/<[^>]*>/i, '') }.map do |item|
76
+ CGI.unescapeHTML(item)
77
+ end
76
78
  opts[:format] = HammerCLI::Options::Normalizers::Enum.new(allowed)
77
79
  elsif param.expected_type.to_s == 'numeric'
78
80
  opts[:format] = HammerCLI::Options::Normalizers::Number.new
@@ -93,80 +93,88 @@ module HammerCLI
93
93
 
94
94
  # Object
95
95
 
96
- def extend_options(command_class)
96
+ def extend_options
97
97
  allowed = @only & %i[command_options option]
98
98
  return if allowed.empty? || (allowed & @except).any?
99
99
 
100
- self.class.extend_options(command_class)
100
+ self.class.extend_options(@command_class)
101
101
  end
102
102
 
103
- def extend_predefined_options(command_class)
103
+ def extend_predefined_options
104
104
  allowed = @only & %i[predefined_options use_option]
105
105
  return if allowed.empty? || (allowed & @except).any?
106
106
 
107
- self.class.extend_predefined_options(command_class)
107
+ self.class.extend_predefined_options(@command_class)
108
108
  end
109
109
 
110
110
  def extend_before_print(data)
111
111
  allowed = @only & %i[before_print data]
112
112
  return if allowed.empty? || (allowed & @except).any?
113
113
 
114
- self.class.extend_before_print(data)
114
+ self.class.extend_before_print(data, @command_object, @command_class)
115
115
  end
116
116
 
117
- def extend_output(command_class)
117
+ def extend_output
118
118
  allowed = @only & %i[output]
119
119
  return if allowed.empty? || (allowed & @except).any?
120
120
 
121
- self.class.extend_output(command_class)
121
+ self.class.extend_output(@command_class, @command_object)
122
122
  end
123
123
 
124
- def extend_help(command_class)
124
+ def extend_help
125
125
  allowed = @only & %i[help]
126
126
  return if allowed.empty? || (allowed & @except).any?
127
127
 
128
- self.class.extend_help(command_class)
128
+ self.class.extend_help(@command_class)
129
129
  end
130
130
 
131
131
  def extend_request_headers(headers)
132
132
  allowed = @only & %i[request_headers headers request]
133
133
  return if allowed.empty? || (allowed & @except).any?
134
134
 
135
- self.class.extend_request_headers(headers)
135
+ self.class.extend_request_headers(headers, @command_object, @command_class)
136
136
  end
137
137
 
138
138
  def extend_request_options(options)
139
139
  allowed = @only & %i[request_options options request]
140
140
  return if allowed.empty? || (allowed & @except).any?
141
141
 
142
- self.class.extend_request_options(options)
142
+ self.class.extend_request_options(options, @command_object, @command_class)
143
143
  end
144
144
 
145
145
  def extend_request_params(params)
146
146
  allowed = @only & %i[request_params params request]
147
147
  return if allowed.empty? || (allowed & @except).any?
148
148
 
149
- self.class.extend_request_params(params)
149
+ self.class.extend_request_params(params, @command_object, @command_class)
150
150
  end
151
151
 
152
- def extend_option_sources(sources, command = nil)
152
+ def extend_option_sources(sources)
153
153
  allowed = @only & %i[option_sources]
154
154
  return if allowed.empty? || (allowed & @except).any?
155
155
 
156
- self.class.extend_option_sources(sources, command)
156
+ self.class.extend_option_sources(sources, @command_object, @command_class)
157
157
  end
158
158
 
159
- def extend_option_family(command_class)
159
+ def extend_option_family
160
160
  allowed = @only & %i[option_family]
161
161
  return if allowed.empty? || (allowed & @except).any?
162
162
 
163
- self.class.extend_option_family(command_class)
163
+ self.class.extend_option_family(@command_class)
164
164
  end
165
165
 
166
166
  def delegatee(command_class)
167
167
  self.class.delegatee = command_class
168
168
  end
169
169
 
170
+ def command_class(command_class)
171
+ @command_class = command_class
172
+ end
173
+
174
+ def command_object(command_object)
175
+ @command_object = command_object
176
+ end
177
+
170
178
  def details
171
179
  except = @except.empty? ? '*nothing*' : @except
172
180
  details = if @only == ALLOWED_EXTENSIONS
@@ -198,17 +206,17 @@ module HammerCLI
198
206
  logger.debug("Added predefined options for #{command_class}: #{@predefined_option_names}")
199
207
  end
200
208
 
201
- def self.extend_before_print(data)
209
+ def self.extend_before_print(data, command_object, command_class)
202
210
  return if @before_print_block.nil?
203
211
 
204
- @before_print_block.call(data)
212
+ @before_print_block.call(data, command_object, command_class)
205
213
  logger.debug("Called block for #{@delegatee} data:\n\t#{@before_print_block}")
206
214
  end
207
215
 
208
- def self.extend_output(command_class)
216
+ def self.extend_output(command_class, command_object)
209
217
  return if @output_extension_block.nil?
210
218
 
211
- @output_extension_block.call(command_class.output_definition)
219
+ @output_extension_block.call(command_class.output_definition, command_object, command_class)
212
220
  logger.debug("Called block for #{@delegatee} output definition:\n\t#{@output_extension_block}")
213
221
  end
214
222
 
@@ -219,31 +227,31 @@ module HammerCLI
219
227
  logger.debug("Saved block for #{@delegatee} help definition:\n\t#{@help_extension_block}")
220
228
  end
221
229
 
222
- def self.extend_request_headers(headers)
230
+ def self.extend_request_headers(headers, command_object, command_class)
223
231
  return if @request_headers_block.nil?
224
232
 
225
- @request_headers_block.call(headers)
233
+ @request_headers_block.call(headers, command_object, command_class)
226
234
  logger.debug("Called block for #{@delegatee} request headers:\n\t#{@request_headers_block}")
227
235
  end
228
236
 
229
- def self.extend_request_options(options)
237
+ def self.extend_request_options(options, command_object, command_class)
230
238
  return if @request_options_block.nil?
231
239
 
232
- @request_options_block.call(options)
240
+ @request_options_block.call(options, command_object, command_class)
233
241
  logger.debug("Called block for #{@delegatee} request options:\n\t#{@request_options_block}")
234
242
  end
235
243
 
236
- def self.extend_request_params(params)
244
+ def self.extend_request_params(params, command_object, command_class)
237
245
  return if @request_params_block.nil?
238
246
 
239
- @request_params_block.call(params)
247
+ @request_params_block.call(params, command_object, command_class)
240
248
  logger.debug("Called block for #{@delegatee} request params:\n\t#{@request_params_block}")
241
249
  end
242
250
 
243
- def self.extend_option_sources(sources, command = nil)
251
+ def self.extend_option_sources(sources, command_object, command_class)
244
252
  return if @option_sources_block.nil?
245
253
 
246
- @option_sources_block.call(sources, command)
254
+ @option_sources_block.call(sources, command_object, command_class)
247
255
  logger.debug("Called block for #{@delegatee} option sources:\n\t#{@option_sources_block}")
248
256
  end
249
257
 
@@ -73,7 +73,7 @@ module HammerCLI::Output
73
73
 
74
74
  data << sets.each_with_object({}) do |set, res|
75
75
  mark = field.sets.include?(set) ? 'x' : ''
76
- value = set == sets.first ? field.full_label : mark
76
+ value = set == sets.first ? field.full_label.capitalize : mark
77
77
  res.update(set => value)
78
78
  end
79
79
  end
@@ -66,7 +66,7 @@ module HammerCLI::Output
66
66
 
67
67
  def include_by_label?(labels, label)
68
68
  labels.any? do |l|
69
- l.start_with?("#{label}/") || label.match(%r{^#{l.gsub(/\*/, '.*')}(|\/.*)$})
69
+ l.start_with?("#{label}/") || label.match(%r{^#{l.gsub(/\*/, '.*')}(|\/.*)$}) || l == label
70
70
  end
71
71
  end
72
72
 
@@ -1,5 +1,5 @@
1
1
  module HammerCLI
2
2
  def self.version
3
- @version ||= Gem::Version.new "2.5.0"
3
+ @version ||= Gem::Version.new "2.5.1"
4
4
  end
5
5
  end
data/man/hammer.1.gz CHANGED
Binary file
@@ -269,9 +269,9 @@ describe HammerCLI::Output::Definition do
269
269
  sets_table = "---------|-----|---------|----\n" \
270
270
  "FIELDS | ALL | DEFAULT | SET\n" \
271
271
  "---------|-----|---------|----\n" \
272
- "newfield | x | x | \n" \
273
- "cf/abc | | | x \n" \
274
- "cf/bca | | | x \n" \
272
+ "Newfield | x | x | \n" \
273
+ "Cf/abc | | | x \n" \
274
+ "Cf/bca | | | x \n" \
275
275
  "---------|-----|---------|----\n"
276
276
 
277
277
  definition.sets_table.must_equal sets_table
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: 2.5.0
4
+ version: 2.5.1
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: 2021-05-04 00:00:00.000000000 Z
12
+ date: 2021-06-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: clamp
@@ -154,28 +154,28 @@ extensions: []
154
154
  extra_rdoc_files:
155
155
  - doc/commands_modification.md
156
156
  - doc/creating_apipie_commands.md
157
+ - doc/creating_commands.md
157
158
  - doc/design.png
158
159
  - doc/design.uml
159
160
  - doc/developer_docs.md
160
161
  - doc/development_tips.md
161
162
  - doc/help_modification.md
162
163
  - doc/i18n.md
164
+ - doc/installation.md
163
165
  - doc/installation_deb.md
164
166
  - doc/installation_gem.md
167
+ - doc/installation_rpm.md
168
+ - doc/installation_source.md
165
169
  - doc/option_builders.md
166
170
  - doc/option_normalizers.md
167
171
  - doc/output.md
168
172
  - doc/review_checklist.md
169
173
  - doc/writing_a_plugin.md
170
174
  - doc/commands_extension.md
171
- - doc/creating_commands.md
172
- - doc/installation_rpm.md
173
- - doc/installation_source.md
174
- - doc/installation.md
175
175
  - doc/release_notes.md
176
176
  - config/cli.modules.d/module_config_template.yml
177
- - config/hammer.completion
178
177
  - config/cli_config.template.yml
178
+ - config/hammer.completion
179
179
  - README.md
180
180
  files:
181
181
  - LICENSE
@@ -394,7 +394,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
394
394
  - !ruby/object:Gem::Version
395
395
  version: '0'
396
396
  requirements: []
397
- rubygems_version: 3.0.8
397
+ rubygems_version: 3.1.2
398
398
  signing_key:
399
399
  specification_version: 4
400
400
  summary: Universal command-line interface
@@ -404,13 +404,15 @@ test_files:
404
404
  - test/functional/nil_values_test.rb
405
405
  - test/functional/test_helper.rb
406
406
  - test/test_helper.rb
407
+ - test/unit/abstract_test.rb
407
408
  - test/unit/apipie/api_connection_test.rb
408
409
  - test/unit/apipie/command_test.rb
410
+ - test/unit/apipie/option_builder_test.rb
409
411
  - test/unit/apipie/option_definition_test.rb
410
412
  - test/unit/apipie/test_helper.rb
411
- - test/unit/apipie/option_builder_test.rb
412
413
  - test/unit/bash_test.rb
413
414
  - test/unit/ca_cert_manager_test.rb
415
+ - test/unit/command_extensions_test.rb
414
416
  - test/unit/completer_test.rb
415
417
  - test/unit/connection_test.rb
416
418
  - test/unit/csv_parser_test.rb
@@ -424,6 +426,7 @@ test_files:
424
426
  - test/unit/fixtures/defaults/defaults_dashed.yml
425
427
  - test/unit/fixtures/json_input/invalid.json
426
428
  - test/unit/fixtures/json_input/valid.json
429
+ - test/unit/help/builder_test.rb
427
430
  - test/unit/help/definition/abstract_item_test.rb
428
431
  - test/unit/help/definition/list_test.rb
429
432
  - test/unit/help/definition/note_test.rb
@@ -431,7 +434,6 @@ test_files:
431
434
  - test/unit/help/definition/text_test.rb
432
435
  - test/unit/help/definition_test.rb
433
436
  - test/unit/help/text_builder_test.rb
434
- - test/unit/help/builder_test.rb
435
437
  - test/unit/history_test.rb
436
438
  - test/unit/i18n_test.rb
437
439
  - test/unit/logger_test.rb
@@ -443,11 +445,11 @@ test_files:
443
445
  - test/unit/options/normalizers_test.rb
444
446
  - test/unit/options/option_collector_test.rb
445
447
  - test/unit/options/option_definition_test.rb
448
+ - test/unit/options/option_family_test.rb
446
449
  - test/unit/options/processor_list_test.rb
447
450
  - test/unit/options/sources/command_line_test.rb
448
451
  - test/unit/options/sources/saved_defaults_test.rb
449
452
  - test/unit/options/validators/dsl_test.rb
450
- - test/unit/options/option_family_test.rb
451
453
  - test/unit/output/adapter/abstract_test.rb
452
454
  - test/unit/output/adapter/base_test.rb
453
455
  - test/unit/output/adapter/csv_test.rb
@@ -464,5 +466,3 @@ test_files:
464
466
  - test/unit/settings_test.rb
465
467
  - test/unit/test_helper.rb
466
468
  - test/unit/utils_test.rb
467
- - test/unit/abstract_test.rb
468
- - test/unit/command_extensions_test.rb