hammer_cli_foreman 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/doc/release_notes.md +13 -0
  3. data/lib/hammer_cli_foreman/command_extensions/subnet.rb +25 -10
  4. data/lib/hammer_cli_foreman/command_extensions/user.rb +9 -5
  5. data/lib/hammer_cli_foreman/commands.rb +1 -2
  6. data/lib/hammer_cli_foreman/compute_attribute.rb +1 -1
  7. data/lib/hammer_cli_foreman/compute_resource.rb +1 -0
  8. data/lib/hammer_cli_foreman/hostgroup.rb +13 -6
  9. data/lib/hammer_cli_foreman/hosts/common_update_options.rb +7 -7
  10. data/lib/hammer_cli_foreman/id_resolver.rb +7 -7
  11. data/lib/hammer_cli_foreman/option_builders.rb +65 -53
  12. data/lib/hammer_cli_foreman/option_sources/id_params.rb +21 -8
  13. data/lib/hammer_cli_foreman/option_sources/ids_params.rb +22 -9
  14. data/lib/hammer_cli_foreman/smart_proxy.rb +7 -5
  15. data/lib/hammer_cli_foreman/template.rb +3 -15
  16. data/lib/hammer_cli_foreman/user.rb +4 -4
  17. data/lib/hammer_cli_foreman/version.rb +1 -1
  18. data/locale/ca/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  19. data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  20. data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  21. data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  22. data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  23. data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  24. data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  25. data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  26. data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  27. data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  28. data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  29. data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  30. data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  31. data/test/data/3.1/foreman_api.json +1 -0
  32. data/test/functional/compute_attribute_test.rb +20 -20
  33. data/test/functional/host_test.rb +34 -0
  34. data/test/functional/hostgroup/create_test.rb +11 -0
  35. data/test/functional/hostgroup/update_test.rb +11 -0
  36. data/test/functional/personal_access_token_test.rb +4 -4
  37. data/test/functional/template_test.rb +74 -14
  38. data/test/functional/user_mail_notification_test.rb +3 -3
  39. data/test/test_helper.rb +1 -1
  40. data/test/unit/commands_test.rb +1 -2
  41. data/test/unit/option_builders_test.rb +88 -83
  42. data/test/unit/option_sources/id_params_test.rb +0 -9
  43. data/test/unit/option_sources/ids_params_test.rb +0 -9
  44. metadata +28 -26
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8287acd52ceb1bea84f8d518c3793d521d084ae771622ea7fc4dcccccd794a1b
4
- data.tar.gz: b557d8fbbc7a451cd09084211c6e8a46a46ef3c198744cbb9c8dc7e861090e93
3
+ metadata.gz: 12d3353f9d530459e2a7f58e8f5603b1f52af4b2ee28aa51c6252bda84f5a5b3
4
+ data.tar.gz: cb323fd78217f8d5b5b1e7b69dd691ea85b3d332dcbbc2e375a668fc7043c298
5
5
  SHA512:
6
- metadata.gz: 283fd640422b5749f6dc9094907bb1c68e72cef15696704f4493f548dd23ca13bd1066fca15616996d4ff6ba48648d904f5633e3cc3305c30464fa9e22c8bf44
7
- data.tar.gz: 94b81f8171c914bdd1435ad00a17c1b1606402bac1ab9b21ca3014056ed285029bc79fe2b0646630d964d3b4715bd94b42a67a35f5399cace731ec44c87e4ee8
6
+ metadata.gz: 04b1444a37f464ab35afdfd3832cf0549448484e9932972603ca5d29d7660a4bd599ab0cae461730a7fca5735712451553983724cbe5a23d8f6ffb0135e5510e
7
+ data.tar.gz: b625099ac29545814e7c73a1d74f0b20559b117bfabac2e2074c448557386c40e81a280ae2fb31271e3e5bd60b1c29c4a60881acfe4d5cbcad3f91cda05ca21c
data/doc/release_notes.md CHANGED
@@ -1,5 +1,18 @@
1
1
  Release notes
2
2
  =============
3
+ ### 3.1.0 (2021-11-10)
4
+ * Update test data for 3.1
5
+ * Make sure provided options override defaults, [#33711](http://projects.theforeman.org/issues/33711)
6
+ * Make template create/update commands use resolver, [#33721](http://projects.theforeman.org/issues/33721)
7
+ * Revert fix rake version
8
+ * Fix rake version
9
+ * Show status once for proxy info ([PR #581](https://github.com/theforeman/hammer-cli-foreman/pull/581)), [#19510](http://projects.theforeman.org/issues/19510)
10
+ * Add proxy status and version to info command ([PR #572](https://github.com/theforeman/hammer-cli-foreman/pull/572))
11
+ * Associate a vm via hammer to a compute resource, [#33047](http://projects.theforeman.org/issues/33047)
12
+ * Fix option builders and tests, [#33226](http://projects.theforeman.org/issues/33226)
13
+ * Bump to 3.1.0-develop
14
+ * Add parent title option for hostgroup, [#32878](http://projects.theforeman.org/issues/32878)
15
+
3
16
  ### 3.0.0 (2021-08-04)
4
17
  * Puppet extraction ([PR #571](https://github.com/theforeman/hammer-cli-foreman/pull/571)), [#33174](http://projects.theforeman.org/issues/33174)
5
18
  * Update rel-eng notebook ([PR #573](https://github.com/theforeman/hammer-cli-foreman/pull/573))
@@ -1,16 +1,7 @@
1
1
  module HammerCLIForeman
2
2
  module CommandExtensions
3
3
  class Subnet < HammerCLI::CommandExtensions
4
- option "--dns", "DNS_NAME", _("DNS Proxy to use within this subnet"),
5
- attribute_name: :option_dns_name,
6
- referenced_resource: :smart_proxy
7
- option "--dhcp", "DHCP_NAME", _("DHCP Proxy to use within this subnet"),
8
- attribute_name: :option_dhcp_name,
9
- referenced_resource: :smart_proxy
10
- option "--tftp", "TFTP_NAME", _("TFTP Proxy to use within this subnet"),
11
- attribute_name: :option_tftp_name,
12
- referenced_resource: :smart_proxy
13
- option "--prefix", "PREFIX", _("Network prefix in CIDR notation (e.g. 64) for this subnet")
4
+ option '--prefix', 'PREFIX', _('Network prefix in CIDR notation (e.g. 64) for this subnet')
14
5
 
15
6
  option_sources do |sources, command|
16
7
  sources.find_by_name('IdResolution').insert_relative(
@@ -20,6 +11,30 @@ module HammerCLIForeman
20
11
  )
21
12
  sources
22
13
  end
14
+
15
+ option_family associate: 'tftp' do
16
+ child '--tftp', 'TFTP_NAME', _('TFTP Proxy to use within this subnet'),
17
+ attribute_name: :option_tftp_name,
18
+ referenced_resource: :smart_proxy
19
+ end
20
+
21
+ option_family associate: 'dns' do
22
+ child '--dns', 'DNS_NAME', _('DNS Proxy to use within this subnet'),
23
+ attribute_name: :option_dns_name,
24
+ referenced_resource: :smart_proxy
25
+ end
26
+
27
+ option_family associate: 'dhcp' do
28
+ child '--dhcp', 'DHCP_NAME', _('DHCP Proxy to use within this subnet'),
29
+ attribute_name: :option_dhcp_name,
30
+ referenced_resource: :smart_proxy
31
+ end
32
+
33
+ option_family associate: 'bmc' do
34
+ child '--bmc', 'BMC_NAME', _('BMC Proxy to use within this subnet'),
35
+ attribute_name: :option_bmc_name,
36
+ referenced_resource: :smart_proxy
37
+ end
23
38
  end
24
39
  end
25
40
  end
@@ -1,17 +1,21 @@
1
1
  module HammerCLIForeman
2
2
  module CommandExtensions
3
3
  class User < HammerCLI::CommandExtensions
4
- option '--default-organization', 'DEFAULT_ORGANIZATION_NAME', _('Default organization name'),
5
- aliased_resource: 'default_organization', referenced_resource: 'default_organization'
6
- option '--default-location', 'DEFAULT_LOCATION_NAME', _('Default location name'),
7
- aliased_resource: 'default_location', referenced_resource: 'default_location'
8
-
9
4
  option '--ask-password', 'ASK_PW', ' ', format: HammerCLI::Options::Normalizers::Bool.new
10
5
 
11
6
  option_sources do |sources, command|
12
7
  sources << HammerCLIForeman::OptionSources::UserParams.new(command)
13
8
  sources
14
9
  end
10
+
11
+ option_family associate: 'default_organization' do
12
+ child '--default-organization', 'DEFAULT_ORGANIZATION_NAME', _('Default organization name'),
13
+ aliased_resource: 'default_organization', referenced_resource: 'organization'
14
+ end
15
+ option_family associate: 'default_location' do
16
+ child '--default-location', 'DEFAULT_LOCATION_NAME', _('Default location name'),
17
+ aliased_resource: 'default_location', referenced_resource: 'location'
18
+ end
15
19
  end
16
20
  end
17
21
  end
@@ -97,9 +97,8 @@ module HammerCLIForeman
97
97
  configurator = BuilderConfigurator.new(searchables, dependency_resolver)
98
98
 
99
99
  builder = ForemanOptionBuilder.new(searchables)
100
- builder.builders = []
100
+ builder.builders = super.builders
101
101
  builder.builders += configurator.builders_for(resource, resource.action(action)) if resource_defined?
102
- builder.builders += super.builders
103
102
  builder
104
103
  end
105
104
 
@@ -12,7 +12,7 @@ module HammerCLIForeman
12
12
  profile = HammerCLIForeman.record_to_common_format(
13
13
  HammerCLIForeman.foreman_resource(:compute_profiles).call(:show, 'id' => options['option_compute_profile_id'] )
14
14
  )
15
- params['compute_attribute'] = profile['compute_attributes'].select { |hash| hash['compute_resource_id'] == options['option_compute_resource_id']}[0] || {}
15
+ params['compute_attribute'] = profile['compute_attributes'].select { |hash| hash['compute_resource_id'].to_s == options['option_compute_resource_id'].to_s}[0] || {}
16
16
  params['compute_attribute'].delete('attributes') if params['compute_attribute']['attributes']
17
17
  params
18
18
  end
@@ -107,6 +107,7 @@ module HammerCLIForeman
107
107
  class AssociateVmsCommand < HammerCLIForeman::Command
108
108
  action :associate
109
109
  command_name 'associate-vms'
110
+ option "--vm-id","VM ID", _("Associate a specific VM")
110
111
  success_message _("Virtual machines have been associated.")
111
112
  failure_message _("Could not associate the virtual machines")
112
113
 
@@ -3,13 +3,20 @@ module HammerCLIForeman
3
3
  module HostgroupUpdateCreateCommons
4
4
 
5
5
  def self.included(base)
6
- base.option "--parent", "PARENT_NAME", _("Name of parent hostgroup")
7
- base.option ["--root-password"], "ROOT_PASSWORD", _("Root password")
8
- base.option ["--ask-root-password", "--ask-root-pass"], "ASK_ROOT_PW", "",
6
+ base.option '--root-password', 'ROOT_PASSWORD', _('Root password')
7
+ base.option '--ask-root-password', 'ASK_ROOT_PW', '',
9
8
  format: HammerCLI::Options::Normalizers::Bool.new
10
- base.option "--subnet6", "SUBNET6_NAME", _("Subnet IPv6 name")
11
9
 
12
10
  base.build_options without: %i[root_pass]
11
+
12
+ base.option_family associate: 'subnet6' do
13
+ child '--subnet6', 'SUBNET6_NAME', _('Subnet IPv6 name')
14
+ end
15
+
16
+ base.option_family associate: 'parent' do
17
+ child '--parent', 'PARENT_NAME', _('Name of parent hostgroup')
18
+ child '--parent-title', 'PARENT_TITLE', _('Title of parent hostgroup')
19
+ end
13
20
  end
14
21
 
15
22
  def self.ask_password
@@ -19,8 +26,8 @@ module HammerCLIForeman
19
26
 
20
27
  def request_params
21
28
  params = super
22
- params['hostgroup']["parent_id"] ||= resolver.hostgroup_id('option_name' => option_parent) if option_parent
23
-
29
+ params['hostgroup']['parent_id'] ||= resolver.hostgroup_id('option_name' => option_parent) if option_parent
30
+ params['hostgroup']['parent_id'] ||= resolver.hostgroup_id('option_title' => option_parent_title) if option_parent_title
24
31
  params['hostgroup']['root_pass'] = option_root_password if option_root_password
25
32
  params['hostgroup']['root_pass'] = HammerCLIForeman::HostgroupUpdateCreateCommons::ask_password if option_ask_root_password
26
33
 
@@ -3,11 +3,12 @@ module HammerCLIForeman
3
3
  module CommonUpdateOptions
4
4
 
5
5
  def self.included(base)
6
- base.option "--owner", "OWNER_LOGIN", _("Login of the owner"),
7
- :attribute_name => :option_user_login
8
- base.option "--owner-id", "OWNER_ID", _("ID of the owner"),
9
- :attribute_name => :option_owner_id
10
-
6
+ base.option_family do
7
+ parent '--owner-id', 'OWNER_ID', _('ID of the owner'),
8
+ attribute_name: :option_owner_id
9
+ child '--owner', 'OWNER_LOGIN', _('Login of the owner'),
10
+ attribute_name: :option_user_login
11
+ end
11
12
  base.option "--root-password", "ROOT_PW",
12
13
  _("Required if host is managed and value is not inherited from host group or default password in settings")
13
14
 
@@ -112,14 +113,13 @@ module HammerCLIForeman
112
113
 
113
114
  private
114
115
 
115
-
116
116
  def owner_id(name, type)
117
117
  return unless name
118
118
  return resolver.usergroup_id('option_name' => name) if type == 'Usergroup'
119
119
 
120
120
  resolver.user_id('option_login' => name)
121
121
  end
122
-
122
+
123
123
  def proxy_id(name)
124
124
  resolver.smart_proxy_id('option_name' => name) if name
125
125
  end
@@ -1,14 +1,12 @@
1
1
  module HammerCLIForeman
2
2
 
3
3
  class Searchable
4
- attr_reader :name, :description, :format
4
+ attr_reader :name, :description
5
5
 
6
6
  def initialize(name, description, options={})
7
7
  @name = name
8
8
  @description = description
9
9
  @editable = options[:editable].nil? ? true : options[:editable]
10
- @format = options[:format]
11
- @parent = options[:parent]
12
10
  end
13
11
 
14
12
  def plural_name
@@ -18,10 +16,6 @@ module HammerCLIForeman
18
16
  def editable?
19
17
  @editable
20
18
  end
21
-
22
- def parent?
23
- @parent
24
- end
25
19
  end
26
20
 
27
21
  class Searchables
@@ -130,6 +124,12 @@ module HammerCLIForeman
130
124
  @searchables.for(resource)
131
125
  end
132
126
 
127
+ def template_kind_id(options = {})
128
+ name = options['option_type'] == 'snippet' ? nil : options['option_type']
129
+ options['option_name'] = name
130
+ get_id(:template_kinds, options)
131
+ end
132
+
133
133
  protected
134
134
 
135
135
  def define_id_finders
@@ -172,8 +172,7 @@ module HammerCLIForeman
172
172
  def build(builder_params={})
173
173
  resource_name_map = builder_params[:resource_mapping] || {}
174
174
  @searchables.for(@resource).collect do |s|
175
- family = HammerCLI::Options::OptionFamily.new
176
- family.parent(
175
+ option(
177
176
  optionamize("--#{s.name}"),
178
177
  s.name.upcase,
179
178
  s.description,
@@ -213,23 +212,43 @@ module HammerCLIForeman
213
212
 
214
213
  def build(builder_params={})
215
214
  resource_name_map = builder_params[:resource_mapping] || {}
216
- dependent_options(@resource, resource_name_map)
215
+ command = builder_params[:command]
216
+ dependent_options(@resource, resource_name_map, command)
217
217
  end
218
218
 
219
219
  protected
220
220
 
221
- def dependent_options(resource, resource_name_map)
221
+ def dependent_options(resource, resource_name_map, command)
222
222
  options = []
223
223
  searchables = @searchables.for(resource)
224
224
  resource_name = resource.singular_name
225
225
  aliased_name = aliased(resource_name, resource_name_map)
226
226
  types = searchables.map(&:name).push('id').map(&:capitalize).join('/')
227
227
  associated_resource = aliased_name.to_s.tr('_', ' ')
228
- family = HammerCLI::Options::OptionFamily.new(
229
- referenced_resource: resource_name,
230
- aliased_resource: aliased_name,
231
- description: _('%{types} of associated %{resource}') % { types: types, resource: associated_resource }
232
- )
228
+ family = command.option_families.find do |f|
229
+ f.head.referenced_resource == resource_name
230
+ end
231
+ unless family
232
+ # If there is no family it probably means that we explicitly want to
233
+ # expand options via
234
+ # build_options do |o|
235
+ # o.expand.including(:resource)
236
+ # end
237
+ # instead of generating it from API docs (it may not be even present there)
238
+ family = HammerCLI::Options::OptionFamily.new(
239
+ description: _('%{types} of associated %{resource}') % { types: types, resource: associated_resource },
240
+ creator: command
241
+ )
242
+ options << family.parent(
243
+ optionamize("--#{aliased_name}-id"),
244
+ "#{aliased_name}_id".upcase,
245
+ description("#{aliased_name}_id", @context[:action]),
246
+ attribute_name: HammerCLI.option_accessor_name("#{resource_name}_id"),
247
+ referenced_resource: resource_name,
248
+ aliased_resource: aliased_name,
249
+ format: HammerCLI::Options::Normalizers::Number.new
250
+ )
251
+ end
233
252
 
234
253
  unless searchables.empty?
235
254
  first = searchables[0]
@@ -240,31 +259,25 @@ module HammerCLIForeman
240
259
  options << family.child(
241
260
  optionamize("--#{aliased_name}"),
242
261
  "#{aliased_name}_#{first.name}".upcase,
243
- first.description || " ",
244
- attribute_name: HammerCLI.option_accessor_name("#{resource_name}_#{first.name}")
262
+ first.description || ' ',
263
+ attribute_name: HammerCLI.option_accessor_name("#{resource_name}_#{first.name}"),
264
+ referenced_resource: resource_name,
265
+ aliased_resource: aliased_name
245
266
  )
246
267
  # Other options are named by the resource plus the searchable name
247
268
  # Eg. --organization-label with accessor option_organization_label
248
269
  remaining.each do |s|
249
- options << family.send(s.parent? ? :parent : :child,
270
+ options << family.child(
250
271
  optionamize("--#{aliased_name}-#{s.name}"),
251
272
  "#{aliased_name}_#{s.name}".upcase,
252
- s.description || " ",
273
+ s.description || ' ',
253
274
  attribute_name: HammerCLI.option_accessor_name("#{resource_name}_#{s.name}"),
254
- format: s.format
275
+ referenced_resource: resource_name,
276
+ aliased_resource: aliased_name
255
277
  )
256
278
  end
257
279
  end
258
280
 
259
- unless options.any? { |o| o.handles?(optionamize("--#{aliased_name}-id")) }
260
- options << family.parent(
261
- optionamize("--#{aliased_name}-id"),
262
- "#{aliased_name}_id".upcase,
263
- description("#{aliased_name}_id", @context[:action]),
264
- attribute_name: HammerCLI.option_accessor_name("#{resource_name}_id"),
265
- format: HammerCLI::Options::Normalizers::Number.new
266
- )
267
- end
268
281
  options
269
282
  end
270
283
 
@@ -285,15 +298,25 @@ module HammerCLIForeman
285
298
  class UpdateDependentSearchablesOptionBuilder < DependentSearchablesOptionBuilder
286
299
  protected
287
300
 
288
- def dependent_options(resource, resource_name_map)
301
+ def dependent_options(resource, resource_name_map, command)
289
302
  options = []
290
303
  searchables = @searchables.for(resource)
291
304
  resource_name = resource.singular_name
292
305
  aliased_name = aliased(resource_name, resource_name_map)
306
+ # Those options are not coming from API docs, thus create a new family only
293
307
  family = HammerCLI::Options::OptionFamily.new(
294
308
  prefix: 'new-',
295
309
  aliased_resource: aliased_name,
296
- referenced_resource: resource_name
310
+ referenced_resource: resource_name,
311
+ creator: command
312
+ )
313
+
314
+ options << family.parent(
315
+ optionamize("--new-#{aliased_name}-id"),
316
+ "new_#{aliased_name}_id".upcase,
317
+ _('Use to update associated %s') % aliased_name,
318
+ attribute_name: HammerCLI.option_accessor_name("new_#{resource_name}_id"),
319
+ format: HammerCLI::Options::Normalizers::Number.new
297
320
  )
298
321
  unless searchables.empty?
299
322
  first = searchables[0]
@@ -304,73 +327,63 @@ module HammerCLIForeman
304
327
  options << family.child(
305
328
  optionamize("--new-#{aliased_name}"),
306
329
  "new_#{aliased_name}_#{first.name}".upcase,
307
- _('Use to update'),
330
+ _('Use to update associated %s') % aliased_name,
308
331
  attribute_name: HammerCLI.option_accessor_name("new_#{resource_name}_#{first.name}")
309
332
  )
310
333
  # Other options are named by the resource plus the searchable name
311
334
  # Eg. --new-organization-label with accessor option_new_organization_label
312
335
  remaining.each do |s|
313
- options << family.send(s.parent? ? :parent : :child,
336
+ options << family.child(
314
337
  optionamize("--new-#{aliased_name}-#{s.name}"),
315
338
  "new_#{aliased_name}_#{s.name}".upcase,
316
- _('Use to update'),
339
+ _('Use to update associated %s') % aliased_name,
317
340
  attribute_name: HammerCLI.option_accessor_name("new_#{resource_name}_#{s.name}")
318
341
  )
319
342
  end
320
343
  end
321
344
 
322
- unless options.any? { |o| o.handles?(optionamize("--new-#{aliased_name}-id")) }
323
- options << family.parent(
324
- optionamize("--new-#{aliased_name}-id"),
325
- "new_#{aliased_name}_id".upcase,
326
- _('Use to update'),
327
- attribute_name: HammerCLI.option_accessor_name("new_#{resource_name}_id"),
328
- format: HammerCLI::Options::Normalizers::Number.new
329
- )
330
- end
331
345
  options
332
346
  end
333
347
  end
334
348
 
335
349
  class DependentSearchablesArrayOptionBuilder < DependentSearchablesOptionBuilder
336
-
337
-
338
- def dependent_options(resource, resource_name_map)
350
+ def dependent_options(resource, resource_name_map, command)
339
351
  options = []
340
352
  searchables = @searchables.for(resource)
341
353
  resource_name = resource.singular_name
342
354
 
343
355
  aliased_name = aliased(resource_name, resource_name_map)
344
356
  aliased_plural_name = aliased(resource.name, resource_name_map)
345
-
346
357
  unless searchables.empty?
347
358
  first = searchables[0]
348
359
  remaining = searchables[1..-1] || []
349
- types = searchables.map(&:plural_name).map(&:capitalize).join('/')
350
- associated_resource = aliased_plural_name.to_s.tr('_', ' ')
351
- family = HammerCLI::Options::OptionFamily.new(
352
- format: HammerCLI::Options::Normalizers::List.new,
353
- referenced_resource: resource_name,
354
- aliased_resource: aliased_name,
355
- description: _('%{types} of associated %{resource}') % { types: types, resource: associated_resource }
356
- )
360
+ # Find family created by HammerCLI::Apipie::OptionBuilder for *_ids options
361
+ family = command.option_families.find do |f|
362
+ f.head.referenced_resource == resource_name && f.formats.include?(HammerCLI::Options::Normalizers::List)
363
+ end
357
364
  # First option is named by the resource
358
365
  # Eg. --organizations with accessor option_organization_names
359
366
  options << family.child(
360
367
  optionamize("--#{aliased_plural_name}"),
361
368
  "#{aliased_name}_#{first.plural_name}".upcase,
362
369
  ' ',
363
- attribute_name: HammerCLI.option_accessor_name("#{resource_name}_#{first.plural_name}")
370
+ attribute_name: HammerCLI.option_accessor_name("#{resource_name}_#{first.plural_name}"),
371
+ format: HammerCLI::Options::Normalizers::List.new,
372
+ referenced_resource: resource_name,
373
+ aliased_resource: aliased_name
364
374
  )
365
375
 
366
376
  # Other options are named by the resource plus the searchable name
367
377
  # Eg. --organization-labels with accessor option_organization_labels
368
378
  remaining.each do |s|
369
- options << family.send(s.parent? ? :parent : :child,
379
+ options << family.child(
370
380
  optionamize("--#{aliased_name}-#{s.plural_name}"),
371
381
  "#{aliased_name}_#{s.plural_name}".upcase,
372
382
  ' ',
373
- attribute_name: HammerCLI.option_accessor_name("#{resource_name}_#{s.plural_name}")
383
+ attribute_name: HammerCLI.option_accessor_name("#{resource_name}_#{s.plural_name}"),
384
+ format: HammerCLI::Options::Normalizers::List.new,
385
+ referenced_resource: resource_name,
386
+ aliased_resource: aliased_name
374
387
  )
375
388
  end
376
389
  end
@@ -421,4 +434,3 @@ module HammerCLIForeman
421
434
  end
422
435
 
423
436
  end
424
-
@@ -6,7 +6,7 @@ module HammerCLIForeman
6
6
  end
7
7
 
8
8
  def param_updatable?(param_resource)
9
- param_resource && @command.respond_to?(HammerCLI.option_accessor_name("#{param_resource.singular_name}_id"))
9
+ param_resource && @command.respond_to?(cli_option_resource_id(param_resource))
10
10
  end
11
11
 
12
12
  def available_id_params
@@ -16,16 +16,23 @@ module HammerCLIForeman
16
16
  def needs_resolving?(param_option, param_resource, all_opts)
17
17
  return false unless param_updatable?(param_resource)
18
18
 
19
- searchables_set = @command.searchables.for(param_resource).any? do |s|
19
+ cli_searchables_set = @command.searchables.for(param_resource).any? do |s|
20
20
  option = HammerCLI.option_accessor_name("#{param_resource.singular_name}_#{s.name}")
21
- !all_opts[option].nil?
21
+ next false unless @command.respond_to?(option)
22
+
23
+ !@command.send(option).nil?
22
24
  end
23
- return all_opts[param_option].nil? unless searchables_set
25
+ if cli_searchables_set
26
+ # Remove set '<resource_name>_id' option to force resolving in case of
27
+ # '<resource_name>_[name|title]' was set from CLI
28
+ all_opts.delete(param_option)
29
+ true
30
+ else
31
+ # Don't resolve if resource id was set via CLI
32
+ return false if @command.send(cli_option_resource_id(param_resource))
24
33
 
25
- # Remove set '<resource_name>_id' option to force resolving in case of
26
- # '<resource_name>_[name|title]' was set
27
- all_opts.delete(param_option)
28
- true
34
+ all_opts[param_option].nil?
35
+ end
29
36
  end
30
37
 
31
38
  def get_options(_defined_options, result)
@@ -63,6 +70,12 @@ module HammerCLIForeman
63
70
  e.resource
64
71
  )
65
72
  end
73
+
74
+ private
75
+
76
+ def cli_option_resource_id(resource)
77
+ HammerCLI.option_accessor_name("#{resource.singular_name}_id")
78
+ end
66
79
  end
67
80
  end
68
81
  end
@@ -6,7 +6,7 @@ module HammerCLIForeman
6
6
  end
7
7
 
8
8
  def param_updatable?(param_resource)
9
- param_resource && @command.respond_to?(HammerCLI.option_accessor_name("#{param_resource.singular_name}_ids"))
9
+ param_resource && @command.respond_to?(cli_option_resource_ids(param_resource))
10
10
  end
11
11
 
12
12
  def available_ids_params
@@ -16,16 +16,23 @@ module HammerCLIForeman
16
16
  def needs_resolving?(param_option, param_resource, all_opts)
17
17
  return false unless param_updatable?(param_resource)
18
18
 
19
- searchables_set = @command.searchables.for(param_resource).any? do |s|
19
+ cli_searchables_set = @command.searchables.for(param_resource).any? do |s|
20
20
  option = HammerCLI.option_accessor_name("#{param_resource.singular_name}_#{s.plural_name}")
21
- !all_opts[option].nil?
22
- end
23
- return all_opts[param_option].nil? unless searchables_set
21
+ next false unless @command.respond_to?(option)
24
22
 
25
- # Remove set '<resource_name>_ids' option to force resolving in case of
26
- # '<resource_name>_[names|titles]' was set
27
- all_opts.delete(param_option)
28
- true
23
+ !@command.send(option).nil?
24
+ end
25
+ if cli_searchables_set
26
+ # Remove set '<resource_name>_ids' option to force resolving in case of
27
+ # '<resource_name>_[names|titles]' were set from CLI
28
+ all_opts.delete(param_option)
29
+ true
30
+ else
31
+ # Don't resolve if resource ids were set via CLI
32
+ return false if @command.send(cli_option_resource_ids(param_resource))
33
+
34
+ all_opts[param_option].nil?
35
+ end
29
36
  end
30
37
 
31
38
  def get_options(_defined_options, result)
@@ -44,6 +51,12 @@ module HammerCLIForeman
44
51
  end
45
52
  result
46
53
  end
54
+
55
+ private
56
+
57
+ def cli_option_resource_ids(resource)
58
+ HammerCLI.option_accessor_name("#{resource.singular_name}_ids")
59
+ end
47
60
  end
48
61
  end
49
62
  end
@@ -10,8 +10,9 @@ module HammerCLIForeman
10
10
  output do
11
11
  field :id, _("Id")
12
12
  field :name, _("Name")
13
+ field :status, _("Status")
13
14
  field :url, _("URL")
14
- field :_features, _( "Features"), Fields::List, :width => 25, :hide_blank => true
15
+ field :_features, _( "Features"), Fields::List, :hide_blank => true
15
16
  end
16
17
 
17
18
  def extend_data(proxy)
@@ -22,12 +23,13 @@ module HammerCLIForeman
22
23
  build_options
23
24
  end
24
25
 
25
-
26
26
  class InfoCommand < HammerCLIForeman::InfoCommand
27
-
28
27
  output ListCommand.output_definition do
29
- collection :features, _("Features"), :numbered => false do
30
- custom_field Fields::Reference
28
+ field :version, _("Version")
29
+ field :hosts_count, _("Host_count")
30
+ collection :features, _("Features") do
31
+ field :name, _('Name')
32
+ field :version, _('Version')
31
33
  end
32
34
  HammerCLIForeman::References.taxonomies(self)
33
35
  HammerCLIForeman::References.timestamps(self)
@@ -5,25 +5,13 @@ module HammerCLIForeman
5
5
  resource :provisioning_templates
6
6
 
7
7
  module TemplateCreateUpdateCommons
8
-
9
8
  def option_snippet
10
9
  option_type && (option_type == "snippet")
11
10
  end
12
11
 
13
- def option_template_kind_id
14
- table = kinds.inject({}){ |result, k| result.update(k["name"] => k["id"]) }
15
- if option_snippet == false && table[option_type].nil?
16
- signal_usage_error _("unknown template kind")
17
- else
18
- table[option_type]
19
- end
20
- end
21
-
22
- def kinds
23
- HammerCLIForeman.collection_to_common_format(
24
- HammerCLIForeman.foreman_resource!(:template_kinds).call(:index))
25
- end
26
-
12
+ # This method is for IdParams option source to make resolver work for
13
+ # --type option
14
+ def option_template_kind_id; end
27
15
  end
28
16
 
29
17
  class ListCommand < HammerCLIForeman::ListCommand