hammer_cli 2.4.0 → 3.0.1
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 -1
- data/doc/commands_extension.md +8 -6
- data/doc/release_notes.md +19 -0
- data/lib/hammer_cli/abstract.rb +46 -19
- data/lib/hammer_cli/apipie/option_builder.rb +3 -1
- data/lib/hammer_cli/command_extensions.rb +36 -28
- data/lib/hammer_cli/options/option_family.rb +17 -10
- data/lib/hammer_cli/output/definition.rb +1 -1
- data/lib/hammer_cli/output/field_filter.rb +1 -1
- data/lib/hammer_cli/shell.rb +1 -1
- data/lib/hammer_cli/utils.rb +1 -1
- data/lib/hammer_cli/version.rb +1 -1
- data/locale/ca/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/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/unit/output/definition_test.rb +3 -3
- metadata +73 -73
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c01e8f5eaffd8ec3cf361847b287268be33771d99a96fe8a6b5370efe91f5a2c
|
4
|
+
data.tar.gz: cecab97ca08ecafe8706258a05c208983985e7029be6386e11c667ad02161641
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c119a18c68d22130baadf51f0673cbb30ccc391ee9e07a0ba3989a2523f78ad492408ec877a0d9eaa01ce4e8f4820d6c1821507bce8ecdde66081f9fa66c712
|
7
|
+
data.tar.gz: 52a024407f37cba6e6dfe326497b897adaaa74a226820460a4832fa407be7ec7ebfb9b3b2eedb49d48e3e56f4d21a768b4eac5f427ac834c82a2b41c2402b3ff
|
data/bin/hammer
CHANGED
data/doc/commands_extension.md
CHANGED
@@ -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,
|
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,24 @@
|
|
1
1
|
Release notes
|
2
2
|
=============
|
3
|
+
### 3.0.1 (2021-11-02)
|
4
|
+
* Remove a space in hammer's shebang, [#33810](http://projects.theforeman.org/issues/33810)
|
5
|
+
|
6
|
+
### 3.0.0 (2021-08-04)
|
7
|
+
* Update rel-eng notebook ([PR #347](https://github.com/theforeman/hammer-cli/pull/347))
|
8
|
+
* Bump version to 3.0-develop
|
9
|
+
* Revert "change from superficial copy to deep copy of fields", [#29093](http://projects.theforeman.org/issues/29093)
|
10
|
+
* Change from superficial copy to deep copy of fields, [#29093](http://projects.theforeman.org/issues/29093)
|
11
|
+
* Add full comparison for fields option, [#31984](http://projects.theforeman.org/issues/31984)
|
12
|
+
* Force capitalized field names in help, [#32444](http://projects.theforeman.org/issues/32444)
|
13
|
+
* Unescape enum validator description, [#32570](http://projects.theforeman.org/issues/32570)
|
14
|
+
* Make cmd object be available in command extensions, [#32568](http://projects.theforeman.org/issues/32568)
|
15
|
+
* Bump to 2.6.0-develop
|
16
|
+
|
17
|
+
### 2.5.0 (2021-05-04)
|
18
|
+
* Better family assignment for options, [#30996](http://projects.theforeman.org/issues/30996)
|
19
|
+
* Bump to 2.5.0-develop
|
20
|
+
* Right usage in help output for aliases, [#31563](http://projects.theforeman.org/issues/31563)
|
21
|
+
|
3
22
|
### 2.4.0 (2021-02-01)
|
4
23
|
* Expand path for bash completion file, [#30639](http://projects.theforeman.org/issues/30639)
|
5
24
|
* Remove release notes written twice
|
data/lib/hammer_cli/abstract.rb
CHANGED
@@ -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
|
-
|
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?
|
194
|
-
|
195
|
-
if option.respond_to?(:
|
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.
|
220
|
-
extension.
|
221
|
-
extension.
|
222
|
-
extension.
|
223
|
-
extension.
|
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
|
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
|
@@ -93,80 +93,88 @@ module HammerCLI
|
|
93
93
|
|
94
94
|
# Object
|
95
95
|
|
96
|
-
def extend_options
|
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
|
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
|
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
|
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
|
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,
|
156
|
+
self.class.extend_option_sources(sources, @command_object, @command_class)
|
157
157
|
end
|
158
158
|
|
159
|
-
def extend_option_family
|
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,
|
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,
|
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 =
|
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(&:
|
23
|
-
|
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(
|
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(
|
30
|
+
format_deprecation_msg(desc, full_msg)
|
31
31
|
else
|
32
|
-
|
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
|
|
data/lib/hammer_cli/shell.rb
CHANGED
data/lib/hammer_cli/utils.rb
CHANGED
@@ -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
|
124
|
+
subcommand = parent_command.find_subcommand(bit)
|
125
125
|
next if subcommand.nil?
|
126
126
|
|
127
127
|
names << if subcommand.names.size > 1
|
data/lib/hammer_cli/version.rb
CHANGED
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
|
-
"
|
273
|
-
"
|
274
|
-
"
|
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:
|
4
|
+
version: 3.0.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-02
|
12
|
+
date: 2021-11-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: clamp
|
@@ -145,34 +145,34 @@ dependencies:
|
|
145
145
|
version: 0.2.0
|
146
146
|
description: 'Hammer cli provides universal extendable CLI interface for ruby apps
|
147
147
|
|
148
|
-
|
148
|
+
'
|
149
149
|
email: mbacovsk@redhat.com
|
150
150
|
executables:
|
151
151
|
- hammer
|
152
152
|
- hammer-complete
|
153
153
|
extensions: []
|
154
154
|
extra_rdoc_files:
|
155
|
-
- doc/
|
156
|
-
- doc/release_notes.md
|
155
|
+
- doc/creating_apipie_commands.md
|
157
156
|
- doc/design.png
|
158
|
-
- doc/
|
159
|
-
- doc/installation.md
|
157
|
+
- doc/design.uml
|
160
158
|
- doc/development_tips.md
|
161
|
-
- doc/
|
162
|
-
- doc/output.md
|
163
|
-
- doc/developer_docs.md
|
159
|
+
- doc/i18n.md
|
164
160
|
- doc/installation_deb.md
|
165
|
-
- doc/option_normalizers.md
|
166
|
-
- doc/installation_rpm.md
|
167
161
|
- doc/installation_gem.md
|
168
|
-
- doc/help_modification.md
|
169
|
-
- doc/creating_commands.md
|
170
|
-
- doc/installation_source.md
|
171
162
|
- doc/option_builders.md
|
172
|
-
- doc/
|
163
|
+
- doc/option_normalizers.md
|
164
|
+
- doc/writing_a_plugin.md
|
165
|
+
- doc/installation_source.md
|
166
|
+
- doc/creating_commands.md
|
167
|
+
- doc/release_notes.md
|
168
|
+
- doc/commands_extension.md
|
169
|
+
- doc/commands_modification.md
|
170
|
+
- doc/developer_docs.md
|
171
|
+
- doc/help_modification.md
|
172
|
+
- doc/installation.md
|
173
|
+
- doc/installation_rpm.md
|
174
|
+
- doc/output.md
|
173
175
|
- doc/review_checklist.md
|
174
|
-
- doc/creating_apipie_commands.md
|
175
|
-
- doc/design.uml
|
176
176
|
- config/cli.modules.d/module_config_template.yml
|
177
177
|
- config/cli_config.template.yml
|
178
178
|
- config/hammer.completion
|
@@ -394,75 +394,75 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
394
394
|
- !ruby/object:Gem::Version
|
395
395
|
version: '0'
|
396
396
|
requirements: []
|
397
|
-
rubygems_version: 3.
|
397
|
+
rubygems_version: 3.1.2
|
398
398
|
signing_key:
|
399
399
|
specification_version: 4
|
400
400
|
summary: Universal command-line interface
|
401
401
|
test_files:
|
402
|
-
- test/
|
403
|
-
- test/
|
404
|
-
- test/
|
405
|
-
- test/
|
406
|
-
- test/
|
407
|
-
- test/unit/csv_parser_test.rb
|
408
|
-
- test/unit/option_builder_test.rb
|
409
|
-
- test/unit/test_helper.rb
|
410
|
-
- test/unit/utils_test.rb
|
402
|
+
- test/functional/defaults_test.rb
|
403
|
+
- test/functional/help_test.rb
|
404
|
+
- test/functional/nil_values_test.rb
|
405
|
+
- test/functional/test_helper.rb
|
406
|
+
- test/test_helper.rb
|
411
407
|
- test/unit/apipie/command_test.rb
|
412
|
-
- test/unit/apipie/
|
408
|
+
- test/unit/apipie/option_definition_test.rb
|
413
409
|
- test/unit/apipie/test_helper.rb
|
414
410
|
- test/unit/apipie/api_connection_test.rb
|
415
|
-
- test/unit/apipie/
|
416
|
-
- test/unit/
|
417
|
-
- test/unit/
|
418
|
-
- test/unit/
|
419
|
-
- test/unit/
|
420
|
-
- test/unit/options/validators/dsl_test.rb
|
421
|
-
- test/unit/options/sources/command_line_test.rb
|
422
|
-
- test/unit/options/sources/saved_defaults_test.rb
|
423
|
-
- test/unit/options/matcher_test.rb
|
424
|
-
- test/unit/options/option_collector_test.rb
|
425
|
-
- test/unit/options/normalizers_test.rb
|
426
|
-
- test/unit/options/option_definition_test.rb
|
427
|
-
- test/unit/settings_test.rb
|
428
|
-
- test/unit/history_test.rb
|
411
|
+
- test/unit/apipie/option_builder_test.rb
|
412
|
+
- test/unit/ca_cert_manager_test.rb
|
413
|
+
- test/unit/completer_test.rb
|
414
|
+
- test/unit/connection_test.rb
|
415
|
+
- test/unit/csv_parser_test.rb
|
429
416
|
- test/unit/defaults_test.rb
|
430
|
-
- test/unit/logger_test.rb
|
431
|
-
- test/unit/output/formatters_test.rb
|
432
|
-
- test/unit/output/record_collection_test.rb
|
433
|
-
- test/unit/output/dsl_test.rb
|
434
|
-
- test/unit/output/definition_test.rb
|
435
|
-
- test/unit/output/output_test.rb
|
436
|
-
- test/unit/output/field_filter_test.rb
|
437
|
-
- test/unit/output/fields_test.rb
|
438
|
-
- test/unit/output/adapter/table_test.rb
|
439
|
-
- test/unit/output/adapter/json_test.rb
|
440
|
-
- test/unit/output/adapter/abstract_test.rb
|
441
|
-
- test/unit/output/adapter/yaml_test.rb
|
442
|
-
- test/unit/output/adapter/csv_test.rb
|
443
|
-
- test/unit/output/adapter/base_test.rb
|
444
|
-
- test/unit/abstract_test.rb
|
445
|
-
- test/unit/i18n_test.rb
|
446
417
|
- test/unit/fixtures/apipie/architectures.json
|
447
418
|
- test/unit/fixtures/apipie/documented.json
|
448
|
-
- test/unit/fixtures/defaults/defaults_dashed.yml
|
449
|
-
- test/unit/fixtures/defaults/defaults.yml
|
450
|
-
- test/unit/fixtures/json_input/valid.json
|
451
|
-
- test/unit/fixtures/json_input/invalid.json
|
452
419
|
- test/unit/fixtures/certs/ca_cert.pem
|
453
420
|
- test/unit/fixtures/certs/non_ca_cert.pem
|
454
|
-
- test/unit/
|
421
|
+
- test/unit/fixtures/defaults/defaults.yml
|
422
|
+
- test/unit/fixtures/defaults/defaults_dashed.yml
|
423
|
+
- test/unit/fixtures/json_input/invalid.json
|
424
|
+
- test/unit/fixtures/json_input/valid.json
|
425
|
+
- test/unit/help/definition/abstract_item_test.rb
|
455
426
|
- test/unit/help/definition/section_test.rb
|
456
427
|
- test/unit/help/definition/list_test.rb
|
457
|
-
- test/unit/help/definition/text_test.rb
|
458
|
-
- test/unit/help/definition/abstract_item_test.rb
|
459
428
|
- test/unit/help/definition/note_test.rb
|
429
|
+
- test/unit/help/definition/text_test.rb
|
460
430
|
- test/unit/help/definition_test.rb
|
461
|
-
- test/unit/help/builder_test.rb
|
462
431
|
- test/unit/help/text_builder_test.rb
|
463
|
-
- test/unit/
|
464
|
-
- test/
|
465
|
-
- test/
|
466
|
-
- test/
|
467
|
-
- test/
|
468
|
-
- test/
|
432
|
+
- test/unit/help/builder_test.rb
|
433
|
+
- test/unit/history_test.rb
|
434
|
+
- test/unit/i18n_test.rb
|
435
|
+
- test/unit/logger_test.rb
|
436
|
+
- test/unit/main_test.rb
|
437
|
+
- test/unit/messages_test.rb
|
438
|
+
- test/unit/modules_test.rb
|
439
|
+
- test/unit/option_builder_test.rb
|
440
|
+
- test/unit/options/matcher_test.rb
|
441
|
+
- test/unit/options/option_collector_test.rb
|
442
|
+
- test/unit/options/processor_list_test.rb
|
443
|
+
- test/unit/options/sources/command_line_test.rb
|
444
|
+
- test/unit/options/sources/saved_defaults_test.rb
|
445
|
+
- test/unit/options/validators/dsl_test.rb
|
446
|
+
- test/unit/options/normalizers_test.rb
|
447
|
+
- test/unit/options/option_family_test.rb
|
448
|
+
- test/unit/options/option_definition_test.rb
|
449
|
+
- test/unit/output/adapter/abstract_test.rb
|
450
|
+
- test/unit/output/adapter/base_test.rb
|
451
|
+
- test/unit/output/adapter/csv_test.rb
|
452
|
+
- test/unit/output/adapter/json_test.rb
|
453
|
+
- test/unit/output/adapter/table_test.rb
|
454
|
+
- test/unit/output/adapter/yaml_test.rb
|
455
|
+
- test/unit/output/dsl_test.rb
|
456
|
+
- test/unit/output/fields_test.rb
|
457
|
+
- test/unit/output/record_collection_test.rb
|
458
|
+
- test/unit/output/definition_test.rb
|
459
|
+
- test/unit/output/field_filter_test.rb
|
460
|
+
- test/unit/output/formatters_test.rb
|
461
|
+
- test/unit/output/output_test.rb
|
462
|
+
- test/unit/settings_test.rb
|
463
|
+
- test/unit/test_helper.rb
|
464
|
+
- test/unit/utils_test.rb
|
465
|
+
- test/unit/bash_test.rb
|
466
|
+
- test/unit/exception_handler_test.rb
|
467
|
+
- test/unit/abstract_test.rb
|
468
|
+
- test/unit/command_extensions_test.rb
|