hammer_cli 2.2.1 → 2.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/bin/hammer-complete +1 -3
  3. data/config/cli_config.template.yml +1 -1
  4. data/doc/commands_extension.md +8 -6
  5. data/doc/installation.md +1 -1
  6. data/doc/installation_source.md +5 -2
  7. data/doc/release_notes.md +28 -1
  8. data/lib/hammer_cli/abstract.rb +46 -19
  9. data/lib/hammer_cli/apipie/option_builder.rb +3 -1
  10. data/lib/hammer_cli/apipie/options.rb +2 -2
  11. data/lib/hammer_cli/bash/prebuild_command.rb +4 -2
  12. data/lib/hammer_cli/command_extensions.rb +36 -28
  13. data/lib/hammer_cli/options/option_family.rb +17 -10
  14. data/lib/hammer_cli/output/definition.rb +1 -1
  15. data/lib/hammer_cli/output/field_filter.rb +1 -1
  16. data/lib/hammer_cli/settings.rb +1 -1
  17. data/lib/hammer_cli/shell.rb +1 -1
  18. data/lib/hammer_cli/utils.rb +1 -1
  19. data/lib/hammer_cli/version.rb +1 -1
  20. data/locale/ca/LC_MESSAGES/hammer-cli.mo +0 -0
  21. data/locale/de/LC_MESSAGES/hammer-cli.mo +0 -0
  22. data/locale/en/LC_MESSAGES/hammer-cli.mo +0 -0
  23. data/locale/en_GB/LC_MESSAGES/hammer-cli.mo +0 -0
  24. data/locale/es/LC_MESSAGES/hammer-cli.mo +0 -0
  25. data/locale/fr/LC_MESSAGES/hammer-cli.mo +0 -0
  26. data/locale/it/LC_MESSAGES/hammer-cli.mo +0 -0
  27. data/locale/ja/LC_MESSAGES/hammer-cli.mo +0 -0
  28. data/locale/ko/LC_MESSAGES/hammer-cli.mo +0 -0
  29. data/locale/pt_BR/LC_MESSAGES/hammer-cli.mo +0 -0
  30. data/locale/ru/LC_MESSAGES/hammer-cli.mo +0 -0
  31. data/locale/zh_CN/LC_MESSAGES/hammer-cli.mo +0 -0
  32. data/locale/zh_TW/LC_MESSAGES/hammer-cli.mo +0 -0
  33. data/man/hammer.1.gz +0 -0
  34. data/test/unit/output/definition_test.rb +3 -3
  35. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d4f350c15926f88971bd4ca5a7c6e2de1a58c4f5500129e61a68b2ab7f3e2643
4
- data.tar.gz: 9ff9f540add2c845efb74fdced769846fe9118a1dcafdab99537a3eb1d9263f9
3
+ metadata.gz: a39815aa1d748fda7475b583f55c801a8391e21a6418aad7e479a3a8754f1412
4
+ data.tar.gz: ffce03a8a4057f28dd21fde44100a7867f7efe2ce2f2f7e2a18dd0b037ce5983
5
5
  SHA512:
6
- metadata.gz: 1540908ed1806938b8bf53819b0884a17bd2e6d095b5f2ab14a8843bb125e49934732546390475d60349ef9a2cc7bcbf44c19af7c8cbe76e1f61786d1b2b9a0a
7
- data.tar.gz: 0c9f1525623225a28472b3221c528b0d03d425507263049b34ff4e0ebf167dc08ea3f9ed6f9014459930639a26935755327cb0a7b339c8f2affaa714179ab09c
6
+ metadata.gz: fdfe7222cc2b1dc5059a62b8cdef4effd09af391d5880fb2f2315d9ca8d20124ffa2aa07aaebc56be6dd01cf988c69490b8a98da86e29fd166949d9d67e257c3
7
+ data.tar.gz: 34ee4d3731a3a4d4e883acb11dd7dcae4b7cdc9ff45cc513642ebef428a67fd33e7072cc37ba4a8d791c0425afbdfbc8506bc032041e0d86b62387f736aeb32e
data/bin/hammer-complete CHANGED
@@ -5,9 +5,7 @@ require 'English'
5
5
  $LOAD_PATH.unshift(File.join(@project_root, 'lib'))
6
6
  HAMMER = ENV['HAMMER'] || File.join(@project_root, 'bin/hammer')
7
7
 
8
- require 'yaml'
9
-
10
- completion_cache_file = ENV['HAMMER_COMPLETION_CACHE'] || '~/.cache/hammer_completion.yml'
8
+ completion_cache_file = ENV['HAMMER_COMPLETION_CACHE'] || '~/.cache/hammer_completion.json'
11
9
  completion_cache_file = File.expand_path(completion_cache_file)
12
10
 
13
11
  # build the cache if it does not exist
@@ -45,7 +45,7 @@
45
45
  #:log_pattern: '[%5l %d %c] %m'
46
46
 
47
47
  # Location of cache for bash completion
48
- :completion_cache_file: '~/.cache/hammer_completion.yml'
48
+ :completion_cache_file: '~/.cache/hammer_completion.json'
49
49
 
50
50
  # SSL auth options
51
51
  #:ssl:
@@ -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/installation.md CHANGED
@@ -144,7 +144,7 @@ executable specified in `/etc/bash_completion.d/hammer`.
144
144
 
145
145
  Bash completion for hammer needs pre-built cache that holds description of
146
146
  all subcommands and its parameters. The cache is located by default in
147
- `~/.cache/hammer_completion.yml`. The location can be changed in hammer's
147
+ `~/.cache/hammer_completion.json`. The location can be changed in hammer's
148
148
  config file. The cache can be built manually with
149
149
  `hammer prebuild-bash-completion` or is built automatically when completion is
150
150
  used and the cache is missing (this may cause slight delay). The cache expires
@@ -8,6 +8,7 @@ Clone and install CLI core
8
8
  ```bash
9
9
  $ git clone https://github.com/theforeman/hammer-cli.git
10
10
  $ cd hammer-cli
11
+ $ bundle install
11
12
  $ rake install
12
13
  $ cd ..
13
14
  ```
@@ -17,6 +18,7 @@ clone plugin with foreman commands
17
18
  ```bash
18
19
  $ git clone https://github.com/theforeman/hammer-cli-foreman.git
19
20
  $ cd hammer-cli-foreman
21
+ $ bundle install
20
22
  $ rake install
21
23
  $ cd ..
22
24
  ```
@@ -25,7 +27,8 @@ and optionally other plugins.
25
27
 
26
28
 
27
29
  #### Step 2: enable and configure the plugins
28
- You'll have to copy configuration files to proper locations manually.
29
- Please check our [configuration instructions](installation.md#configuration)
30
+ - Add the plugin as a gem to `Gemfile.local.rb`
31
+ - Copy the configuration files to proper locations manually,
32
+ please check our [configuration instructions](installation.md#configuration)
30
33
  and see how to proceed.
31
34
 
data/doc/release_notes.md CHANGED
@@ -1,7 +1,34 @@
1
1
  Release notes
2
2
  =============
3
- ### 2.2.1 (2020-09-04)
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
+
9
+ ### 2.5.0 (2021-05-04)
10
+ * Better family assignment for options, [#30996](http://projects.theforeman.org/issues/30996)
11
+ * Bump to 2.5.0-develop
12
+ * Right usage in help output for aliases, [#31563](http://projects.theforeman.org/issues/31563)
13
+
14
+ ### 2.4.0 (2021-02-01)
15
+ * Expand path for bash completion file, [#30639](http://projects.theforeman.org/issues/30639)
16
+ * Remove release notes written twice
17
+ * Bump to 2.4.0-develop
18
+
19
+ ### 2.3.0 (2020-11-03)
20
+ * Stop sending empty compute attrs param, [#30815](http://projects.theforeman.org/issues/30815)
4
21
  * Make fuzzy search work in hammer shell ([PR #335](https://github.com/theforeman/hammer-cli/pull/335)), [#30747](http://projects.theforeman.org/issues/30747)
22
+ * Add details to installation from source doc ([PR #334](https://github.com/theforeman/hammer-cli/pull/334)), [#30666](http://projects.theforeman.org/issues/30666)
23
+ * Bump to 2.3.0-develop
24
+ * Bump to 2.2.0
25
+
26
+ ### 2.2.0 (2020-08-11)
27
+ * Update installation_rpm.md ([PR #333](https://github.com/theforeman/hammer-cli/pull/333))
28
+ * Clean gem_release.ipynb up
29
+ * Replace awesome_print with amazing_print ([PR #330](https://github.com/theforeman/hammer-cli/pull/330)), [#29846](http://projects.theforeman.org/issues/29846)
30
+ * Fix typo: s/filed/feild/ ([PR #331](https://github.com/theforeman/hammer-cli/pull/331))
31
+ * Bump to 2.2.0-develop
5
32
 
6
33
  ### 2.1.0 (2020-05-14)
7
34
  * Hammer full-help returns correct output, [#29697](http://projects.theforeman.org/issues/29697)
@@ -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
@@ -190,18 +199,9 @@ module HammerCLI
190
199
 
191
200
  option_builder.build(builder_params).each do |option|
192
201
  # skip switches that are already defined
193
- next if option.nil? or option.switches.any? {|s| find_option(s) }
194
-
195
- if option.respond_to?(:referenced_resource)
196
- # Collect options that don't have family, but related to this parent.
197
- children = find_options(
198
- referenced_resource: option.referenced_resource.to_s,
199
- aliased_resource: option.aliased_resource.to_s
200
- ).select { |o| o.family.nil? || o.family.head.nil? }
201
- children.each do |child|
202
- option.family.adopt(child) if option.family
203
- end
204
- end
202
+ next if option.nil? || option.switches.any? { |s| find_option(s) }
203
+
204
+ adjust_family(option) if option.respond_to?(:family)
205
205
  declared_options << option
206
206
  block ||= option.default_conversion_block
207
207
  define_accessors_for(option, &block)
@@ -216,11 +216,12 @@ module HammerCLI
216
216
  raise ArgumentError, _('Command extensions should be inherited from %s.') % HammerCLI::CommandExtensions
217
217
  end
218
218
  extension.delegatee(self)
219
- extension.extend_predefined_options(self)
220
- extension.extend_options(self)
221
- extension.extend_option_family(self)
222
- extension.extend_output(self)
223
- 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
224
225
  logger('Extensions').info "Applied #{extension.details} on #{self}."
225
226
  command_extensions << extension
226
227
  end
@@ -368,7 +369,7 @@ module HammerCLI
368
369
 
369
370
  sources = HammerCLI::Options::ProcessorList.new([sources])
370
371
  self.class.command_extensions.each do |extension|
371
- extension.extend_option_sources(sources, self)
372
+ extension.extend_option_sources(sources)
372
373
  end
373
374
  sources
374
375
  end
@@ -411,6 +412,32 @@ module HammerCLI
411
412
 
412
413
  private
413
414
 
415
+ def self.adjust_family(option)
416
+ # Collect options that should share the same family
417
+ # If those options have family, adopt the current one
418
+ # Else adopt those options to the family of the current option
419
+ # NOTE: this shouldn't rewrite any options,
420
+ # although options from similar family could be adopted (appended)
421
+ options = find_options(
422
+ aliased_resource: option.aliased_resource.to_s
423
+ ).select { |o| o.family.nil? || o.family.formats.include?(option.value_formatter.class) }.group_by do |o|
424
+ next :to_skip if option.family.children.include?(o)
425
+ next :to_adopt if o.family.nil? || o.family.head.nil?
426
+ next :to_skip if o.family.children.include?(option)
427
+ # If both family heads handle the same switch
428
+ # then `option` is probably from similar family and can be adopted
429
+ next :adopt_by if option.family.head.nil? || o.family.head.handles?(option.family.head.long_switch)
430
+
431
+ :to_skip
432
+ end
433
+ options[:to_adopt]&.each do |child|
434
+ option.family&.adopt(child)
435
+ end
436
+ options[:adopt_by]&.map(&:family)&.uniq&.each do |family|
437
+ family.adopt(option)
438
+ end
439
+ end
440
+
414
441
  def self.inherited_output_definition
415
442
  od = nil
416
443
  if superclass.respond_to? :output_definition
@@ -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
@@ -10,11 +10,11 @@ module HammerCLI::Apipie
10
10
  opts = {}
11
11
 
12
12
  params.each do |p|
13
- if p.expected_type == :hash
13
+ if p.expected_type == :hash && !p.params.empty?
14
14
  opts[p.name] = method_options_for_params(p.params, options)
15
15
  else
16
16
  p_name = HammerCLI.option_accessor_name(p.name)
17
- if options.has_key?(p_name)
17
+ if options.key?(p_name)
18
18
  opts[p.name] = options[p_name]
19
19
  elsif respond_to?(p_name, true)
20
20
  opt = send(p_name)
@@ -3,10 +3,12 @@ module HammerCLI
3
3
  class PrebuildCompletionCommand < HammerCLI::AbstractCommand
4
4
  def execute
5
5
  map = HammerCLI::MainCommand.completion_map
6
- cache_file = HammerCLI::Settings.get(:completion_cache_file)
6
+ cache_file = File.expand_path(
7
+ HammerCLI::Settings.get(:completion_cache_file)
8
+ )
7
9
  cache_dir = File.dirname(cache_file)
8
10
  FileUtils.mkdir_p(cache_dir) unless File.directory?(cache_dir)
9
- File.write(File.expand_path(cache_file), map.to_json)
11
+ File.write(cache_file, map.to_json)
10
12
 
11
13
  HammerCLI::EX_OK
12
14
  end
@@ -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
 
@@ -5,7 +5,7 @@ module HammerCLI
5
5
  class OptionFamily
6
6
  attr_reader :children
7
7
 
8
- IDS_REGEX = /\s?([Ii][Dd][s]?)\W|([Ii][Dd][s]?\Z)/
8
+ IDS_REGEX = /(\A[Ii][Dd][s]?)|\s([Ii][Dd][s]?)\W|([Ii][Dd][s]?\Z)/
9
9
 
10
10
  def initialize(options = {})
11
11
  @all = []
@@ -13,26 +13,32 @@ module HammerCLI
13
13
  @options = options
14
14
  @creator = options[:creator] || Class.new(HammerCLI::Apipie::Command)
15
15
  @prefix = options[:prefix]
16
- @description = options[:description]
17
16
  @root = options[:root] || options[:aliased_resource] || options[:referenced_resource]
18
17
  end
19
18
 
20
19
  def description
21
20
  types = all.map(&:type).map { |s| s.split('_').last.to_s }
22
- .map(&:capitalize).join('/')
23
- @description ||= @parent.help[1].gsub(IDS_REGEX) { |w| w.gsub(/\w+/, types) }
21
+ .map(&:downcase).join('/')
22
+ parent_desc = @parent.help[1].gsub(IDS_REGEX) { |w| w.gsub(/\w+/, types) }
23
+ desc = parent_desc.strip.empty? ? @options[:description] : parent_desc
24
24
  if @options[:deprecation].class <= String
25
- format_deprecation_msg(@description, _('Deprecated: %{deprecated_msg}') % { deprecated_msg: @options[:deprecation] })
25
+ format_deprecation_msg(desc, _('Deprecated: %{deprecated_msg}') % { deprecated_msg: @options[:deprecation] })
26
26
  elsif @options[:deprecation].class <= Hash
27
27
  full_msg = @options[:deprecation].map do |flag, msg|
28
28
  _('%{flag} is deprecated: %{deprecated_msg}') % { flag: flag, deprecated_msg: msg }
29
29
  end.join(', ')
30
- format_deprecation_msg(@description, full_msg)
30
+ format_deprecation_msg(desc, full_msg)
31
31
  else
32
- @description
32
+ desc
33
33
  end
34
34
  end
35
35
 
36
+ def formats
37
+ return [@options[:format].class] if @options[:format]
38
+
39
+ all.map(&:value_formatter).map(&:class).uniq
40
+ end
41
+
36
42
  def switch
37
43
  return if @parent.nil? && @children.empty?
38
44
  return @parent.help_lhs.strip if @children.empty?
@@ -67,6 +73,9 @@ module HammerCLI
67
73
  end
68
74
 
69
75
  def adopt(child)
76
+ raise ArgumentError, 'Parent cannot be a child within the same family' if child == @parent
77
+ raise ArgumentError, 'Child is already in the family' if @children.include?(child)
78
+
70
79
  child.family = self
71
80
  @children << child
72
81
  end
@@ -103,9 +112,7 @@ module HammerCLI
103
112
  max_len.downto(0) do |curr_len|
104
113
  0.upto(max_len - curr_len) do |start|
105
114
  root = shortest[start, curr_len]
106
- if switches.all? { |switch| switch.include?(root) }
107
- return root[2..-1].chomp('-')
108
- end
115
+ return root[2..-1].chomp('-') if switches.all? { |switch| switch.include?(root) }
109
116
  end
110
117
  end
111
118
  end
@@ -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
 
@@ -67,7 +67,7 @@ module HammerCLI
67
67
  def self.default_settings
68
68
  {
69
69
  :use_defaults => true,
70
- :completion_cache_file => '~/.cache/hammer_completion.yml'
70
+ :completion_cache_file => '~/.cache/hammer_completion.json'
71
71
  }
72
72
  end
73
73
 
@@ -97,7 +97,7 @@ module HammerCLI
97
97
  history.push(line)
98
98
 
99
99
  line = HammerCLI::CompleterLine.new(line)
100
- ShellMainCommand.run('', line, context) unless line.empty?
100
+ ShellMainCommand.run('hammer', line, context) unless line.empty?
101
101
  end
102
102
  rescue Interrupt; end
103
103
 
@@ -121,7 +121,7 @@ module HammerCLI
121
121
  bits = path.split(' ')
122
122
  parent_command = HammerCLI::MainCommand
123
123
  new_path = (bits[1..-1] || []).each_with_object([]) do |bit, names|
124
- subcommand = parent_command.find_subcommand(bit, fuzzy: false)
124
+ subcommand = parent_command.find_subcommand(bit)
125
125
  next if subcommand.nil?
126
126
 
127
127
  names << if subcommand.names.size > 1
@@ -1,5 +1,5 @@
1
1
  module HammerCLI
2
2
  def self.version
3
- @version ||= Gem::Version.new "2.2.1"
3
+ @version ||= Gem::Version.new "2.5.1"
4
4
  end
5
5
  end
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
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.2.1
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: 2020-09-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
@@ -152,7 +152,6 @@ executables:
152
152
  - hammer-complete
153
153
  extensions: []
154
154
  extra_rdoc_files:
155
- - doc/commands_extension.md
156
155
  - doc/commands_modification.md
157
156
  - doc/creating_apipie_commands.md
158
157
  - doc/creating_commands.md
@@ -165,13 +164,14 @@ extra_rdoc_files:
165
164
  - doc/installation.md
166
165
  - doc/installation_deb.md
167
166
  - doc/installation_gem.md
167
+ - doc/installation_rpm.md
168
+ - doc/installation_source.md
168
169
  - doc/option_builders.md
169
170
  - doc/option_normalizers.md
170
171
  - doc/output.md
171
172
  - doc/review_checklist.md
172
173
  - doc/writing_a_plugin.md
173
- - doc/installation_rpm.md
174
- - doc/installation_source.md
174
+ - doc/commands_extension.md
175
175
  - doc/release_notes.md
176
176
  - config/cli.modules.d/module_config_template.yml
177
177
  - config/cli_config.template.yml
@@ -456,13 +456,13 @@ test_files:
456
456
  - test/unit/output/adapter/json_test.rb
457
457
  - test/unit/output/adapter/table_test.rb
458
458
  - test/unit/output/adapter/yaml_test.rb
459
- - test/unit/output/definition_test.rb
460
459
  - test/unit/output/dsl_test.rb
461
460
  - test/unit/output/field_filter_test.rb
462
461
  - test/unit/output/fields_test.rb
463
462
  - test/unit/output/formatters_test.rb
464
463
  - test/unit/output/output_test.rb
465
464
  - test/unit/output/record_collection_test.rb
465
+ - test/unit/output/definition_test.rb
466
466
  - test/unit/settings_test.rb
467
467
  - test/unit/test_helper.rb
468
468
  - test/unit/utils_test.rb