hammer_cli_foreman 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of hammer_cli_foreman might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/doc/release_notes.md +18 -0
- data/lib/hammer_cli_foreman.rb +4 -0
- data/lib/hammer_cli_foreman/auth_source.rb +10 -0
- data/lib/hammer_cli_foreman/auth_source_ldap.rb +70 -0
- data/lib/hammer_cli_foreman/commands.rb +47 -3
- data/lib/hammer_cli_foreman/credentials.rb +35 -4
- data/lib/hammer_cli_foreman/exceptions.rb +10 -1
- data/lib/hammer_cli_foreman/external_usergroup.rb +83 -0
- data/lib/hammer_cli_foreman/host.rb +26 -22
- data/lib/hammer_cli_foreman/hostgroup.rb +12 -5
- data/lib/hammer_cli_foreman/i18n.rb +4 -0
- data/lib/hammer_cli_foreman/id_resolver.rb +81 -13
- data/lib/hammer_cli_foreman/operating_system.rb +5 -44
- data/lib/hammer_cli_foreman/option_builders.rb +64 -5
- data/lib/hammer_cli_foreman/organization.rb +3 -3
- data/lib/hammer_cli_foreman/param_filters.rb +18 -2
- data/lib/hammer_cli_foreman/references.rb +9 -1
- data/lib/hammer_cli_foreman/role.rb +2 -5
- data/lib/hammer_cli_foreman/usergroup.rb +4 -0
- data/lib/hammer_cli_foreman/version.rb +1 -1
- data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/de/hammer-cli-foreman.po +2169 -0
- data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/en/hammer-cli-foreman.po +1 -1
- data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/en_GB/hammer-cli-foreman.po +254 -81
- data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/es/hammer-cli-foreman.po +268 -94
- data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/fr/hammer-cli-foreman.po +258 -84
- data/locale/hammer-cli-foreman.pot +428 -321
- data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/it/hammer-cli-foreman.po +2168 -0
- data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/ja/hammer-cli-foreman.po +2167 -0
- data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/ko/hammer-cli-foreman.po +2167 -0
- data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/pt_BR/hammer-cli-foreman.po +2167 -0
- data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/ru/hammer-cli-foreman.po +2166 -0
- data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/zh_CN/hammer-cli-foreman.po +2166 -0
- data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/zh_TW/hammer-cli-foreman.po +2166 -0
- data/test/unit/auth_source_ldap_test.rb +95 -0
- data/test/unit/credentials_test.rb +20 -7
- data/test/unit/data/1.6/foreman_api.json +1 -1
- data/test/unit/data/1.6/foreman_api_back.json +1 -0
- data/test/unit/data/1.6/whatever.json +1 -0
- data/test/unit/external_usergroup_test.rb +103 -0
- data/test/unit/helpers/command.rb +5 -1
- data/test/unit/host_test.rb +4 -4
- data/test/unit/hostgroup_test.rb +5 -5
- data/test/unit/media_test.rb +2 -2
- data/test/unit/operating_system_test.rb +7 -1
- data/test/unit/param_filters_test.rb +65 -0
- data/test/unit/smart_class_parameter_test.rb +1 -1
- metadata +335 -309
- data/lib/hammer_cli_foreman/smart_variables.rb +0 -111
@@ -6,18 +6,21 @@ module HammerCLIForeman
|
|
6
6
|
module HostgroupUpdateCreateCommons
|
7
7
|
|
8
8
|
def self.included(base)
|
9
|
-
base.option "--
|
9
|
+
base.option "--puppet-class-ids", "PUPPETCLASS_IDS", _("List of puppetclass ids"),
|
10
10
|
:format => HammerCLI::Options::Normalizers::List.new
|
11
11
|
base.option "--puppet-ca-proxy", "PUPPET_CA_PROXY_NAME", _("Name of puppet CA proxy")
|
12
12
|
base.option "--puppet-proxy", "PUPPET_PROXY_NAME", _("Name of puppet proxy")
|
13
|
+
base.option "--parent", "PARENT_NAME", _("Name of parent hostgroup")
|
14
|
+
base.option "--puppet-classes", "PUPPET_CLASS_NAMES", "",
|
15
|
+
:format => HammerCLI::Options::Normalizers::List.new
|
13
16
|
end
|
14
17
|
|
15
18
|
def request_params
|
16
19
|
params = super
|
17
|
-
|
20
|
+
params['hostgroup']["parent_id"] ||= resolver.hostgroup_id('option_name' => option_parent) if option_parent
|
18
21
|
params['hostgroup']["puppet_proxy_id"] ||= proxy_id(option_puppet_proxy)
|
19
22
|
params['hostgroup']["puppet_ca_proxy_id"] ||= proxy_id(option_puppet_ca_proxy)
|
20
|
-
params['hostgroup']['puppetclass_ids'] =
|
23
|
+
params['hostgroup']['puppetclass_ids'] = option_puppet_class_ids || puppet_class_ids(option_puppet_classes)
|
21
24
|
params
|
22
25
|
end
|
23
26
|
|
@@ -27,6 +30,10 @@ module HammerCLIForeman
|
|
27
30
|
resolver.smart_proxy_id('option_name' => name) if name
|
28
31
|
end
|
29
32
|
|
33
|
+
def puppet_class_ids(names)
|
34
|
+
resolver.puppetclass_ids('option_names' => names) if names
|
35
|
+
end
|
36
|
+
|
30
37
|
end
|
31
38
|
|
32
39
|
class Hostgroup < HammerCLIForeman::Command
|
@@ -38,11 +45,10 @@ module HammerCLIForeman
|
|
38
45
|
output do
|
39
46
|
field :id, _("Id")
|
40
47
|
field :name, _("Name")
|
41
|
-
field :
|
48
|
+
field :title, _("Title")
|
42
49
|
field nil, _("Operating System"), Fields::SingleReference, :key => :operatingsystem
|
43
50
|
field nil, _("Environment"), Fields::SingleReference, :key => :environment
|
44
51
|
field nil, _("Model"), Fields::SingleReference, :key => :model
|
45
|
-
field :ancestry, _("Ancestry")
|
46
52
|
end
|
47
53
|
|
48
54
|
build_options
|
@@ -64,6 +70,7 @@ module HammerCLIForeman
|
|
64
70
|
HammerCLIForeman::References.puppetclasses(self)
|
65
71
|
HammerCLIForeman::References.parameters(self)
|
66
72
|
HammerCLIForeman::References.taxonomies(self)
|
73
|
+
field :ancestry, _("Parent Id")
|
67
74
|
end
|
68
75
|
|
69
76
|
build_options
|
@@ -10,6 +10,10 @@ module HammerCLIForeman
|
|
10
10
|
|
11
11
|
attr_reader :name, :description
|
12
12
|
|
13
|
+
def plural_name
|
14
|
+
ApipieBindings::Inflector.pluralize(@name)
|
15
|
+
end
|
16
|
+
|
13
17
|
def editable?
|
14
18
|
@editable
|
15
19
|
end
|
@@ -37,12 +41,12 @@ module HammerCLIForeman
|
|
37
41
|
:filter => [],
|
38
42
|
:host => [ s_name(_("Host name")) ],
|
39
43
|
:hostgroup => [ s_name(_("Hostgroup name")) ],
|
40
|
-
:image => [],
|
44
|
+
# :image => [],
|
41
45
|
:location => [ s_name(_("Location name")) ],
|
42
46
|
:medium => [ s_name(_("Medium name")) ],
|
43
47
|
:model => [ s_name(_("Model name")) ],
|
44
48
|
:organization => [ s_name(_("Organization name")) ],
|
45
|
-
:operatingsystem => [],
|
49
|
+
:operatingsystem => [ s("title", _("Operating system title"), :editable => false) ],
|
46
50
|
:ptable => [ s_name(_("Partition table name")) ],
|
47
51
|
:proxy => [ s_name(_("Proxy name")) ],
|
48
52
|
:puppetclass => [ s_name(_("Puppet class name")) ],
|
@@ -81,6 +85,7 @@ module HammerCLIForeman
|
|
81
85
|
return scoped_options unless resource
|
82
86
|
|
83
87
|
option_names = searchables(resource).map { |s| s.name }
|
88
|
+
option_names += searchables(resource).map { |s| s.plural_name }
|
84
89
|
option_names << "id"
|
85
90
|
|
86
91
|
option_names.each do |name|
|
@@ -98,15 +103,35 @@ module HammerCLIForeman
|
|
98
103
|
end
|
99
104
|
|
100
105
|
|
106
|
+
def puppetclass_id(options)
|
107
|
+
if options[HammerCLI.option_accessor_name("id")]
|
108
|
+
return options[HammerCLI.option_accessor_name("id")]
|
109
|
+
else
|
110
|
+
resource = @api.resource(:puppetclasses)
|
111
|
+
results = resolved_call(:puppetclasses, :index, options)[0]
|
112
|
+
results = results.values.flatten
|
113
|
+
return pick_result(results, resource)['id']
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def puppetclass_ids(options)
|
118
|
+
options[HammerCLI.option_accessor_name("ids")] || find_resources(:puppetclasses, options).collect{|h| h.values}.flatten.map{|h| h['id']}
|
119
|
+
end
|
120
|
+
|
101
121
|
protected
|
102
122
|
|
103
123
|
def define_id_finders
|
104
124
|
@api.resources.each do |resource|
|
105
125
|
method_name = "#{resource.singular_name}_id"
|
126
|
+
plural_method_name = "#{resource.singular_name}_ids"
|
106
127
|
|
107
128
|
self.class.send(:define_method, method_name) do |options|
|
108
129
|
get_id(resource.name, options)
|
109
130
|
end unless respond_to?(method_name)
|
131
|
+
|
132
|
+
self.class.send(:define_method, plural_method_name) do |options|
|
133
|
+
get_ids(resource.name, options)
|
134
|
+
end unless respond_to?(plural_method_name)
|
110
135
|
end
|
111
136
|
end
|
112
137
|
|
@@ -114,31 +139,57 @@ module HammerCLIForeman
|
|
114
139
|
options[HammerCLI.option_accessor_name("id")] || find_resource(resource_name, options)['id']
|
115
140
|
end
|
116
141
|
|
142
|
+
def get_ids(resource_name, options)
|
143
|
+
options[HammerCLI.option_accessor_name("ids")] || find_resources(resource_name, options).map{|r| r['id']}
|
144
|
+
end
|
145
|
+
|
146
|
+
def find_resources(resource_name, options)
|
147
|
+
resource = @api.resource(resource_name)
|
148
|
+
results = resolved_call(resource_name, :index, options)
|
149
|
+
raise ResolverError.new(_("one of %s not found") % resource.name, resource) if results.count < expected_record_count(options, resource)
|
150
|
+
results
|
151
|
+
end
|
152
|
+
|
117
153
|
def find_resource(resource_name, options)
|
118
154
|
resource = @api.resource(resource_name)
|
155
|
+
results = resolved_call(resource_name, :index, options)
|
156
|
+
pick_result(results, resource)
|
157
|
+
end
|
158
|
+
|
159
|
+
def resolved_call(resource_name, action_name, options)
|
160
|
+
resource = @api.resource(resource_name)
|
161
|
+
action = resource.action(action_name)
|
119
162
|
|
120
163
|
search_options = search_options(options, resource)
|
121
|
-
IdParamsFilter.new(:only_required => true).for_action(
|
164
|
+
IdParamsFilter.new(:only_required => true).for_action(action).each do |param|
|
122
165
|
search_options[param.name] ||= send(param.name, scoped_options(param.name.gsub(/_id$/, ""), options))
|
123
166
|
end
|
124
|
-
|
167
|
+
search_options = route_options(options, action).merge(search_options)
|
168
|
+
|
169
|
+
results = resource.call(action_name, search_options)
|
170
|
+
results = HammerCLIForeman.collection_to_common_format(results)
|
171
|
+
results
|
172
|
+
end
|
173
|
+
|
174
|
+
def route_options(options, action)
|
175
|
+
return {} if action.routes.any? { |r| r.params_in_path.empty? }
|
176
|
+
|
177
|
+
route_options = {}
|
178
|
+
|
179
|
+
action.routes.each do |route|
|
125
180
|
route.params_in_path.each do |param|
|
126
181
|
key = HammerCLI.option_accessor_name(param.to_s)
|
127
182
|
if options[key]
|
128
|
-
|
183
|
+
route_options[param] ||= options[key]
|
129
184
|
end
|
130
185
|
end
|
131
186
|
end
|
132
|
-
|
133
|
-
results = resource.call(:index, search_options)
|
134
|
-
results = HammerCLIForeman.collection_to_common_format(results)
|
135
|
-
|
136
|
-
pick_result(results, resource)
|
187
|
+
route_options
|
137
188
|
end
|
138
189
|
|
139
190
|
def pick_result(results, resource)
|
140
|
-
raise ResolverError.new(_("%s not found") % resource.singular_name) if results.empty?
|
141
|
-
raise ResolverError.new(_("%s found more than once") % resource.singular_name) if results.count > 1
|
191
|
+
raise ResolverError.new(_("%s not found") % resource.singular_name, resource) if results.empty?
|
192
|
+
raise ResolverError.new(_("%s found more than once") % resource.singular_name, resource) if results.count > 1
|
142
193
|
results[0]
|
143
194
|
end
|
144
195
|
|
@@ -149,7 +200,7 @@ module HammerCLIForeman
|
|
149
200
|
else
|
150
201
|
create_search_options(options, resource)
|
151
202
|
end
|
152
|
-
raise MissingSeachOptions.new(_("Missing options to search %s") % resource.singular_name) if search_options.empty?
|
203
|
+
raise MissingSeachOptions.new(_("Missing options to search %s") % resource.singular_name, resource) if search_options.empty?
|
153
204
|
search_options
|
154
205
|
end
|
155
206
|
|
@@ -157,11 +208,28 @@ module HammerCLIForeman
|
|
157
208
|
@searchables.for(resource)
|
158
209
|
end
|
159
210
|
|
211
|
+
def expected_record_count(options, resource)
|
212
|
+
searchables(resource).each do |s|
|
213
|
+
value = options[HammerCLI.option_accessor_name(s.name.to_s)]
|
214
|
+
values = options[HammerCLI.option_accessor_name(s.plural_name.to_s)]
|
215
|
+
if value
|
216
|
+
return 1
|
217
|
+
elsif values
|
218
|
+
return values.count
|
219
|
+
end
|
220
|
+
end
|
221
|
+
0
|
222
|
+
end
|
223
|
+
|
160
224
|
def create_search_options(options, resource)
|
161
225
|
searchables(resource).each do |s|
|
162
226
|
value = options[HammerCLI.option_accessor_name(s.name.to_s)]
|
227
|
+
values = options[HammerCLI.option_accessor_name(s.plural_name.to_s)]
|
163
228
|
if value
|
164
229
|
return {:search => "#{s.name} = \"#{value}\""}
|
230
|
+
elsif values
|
231
|
+
query = values.map{|v| "#{s.name} = \"#{v}\"" }.join(" or ")
|
232
|
+
return {:search => query}
|
165
233
|
end
|
166
234
|
end
|
167
235
|
{}
|
@@ -8,7 +8,7 @@ module HammerCLIForeman
|
|
8
8
|
|
9
9
|
output do
|
10
10
|
field :id, _("Id")
|
11
|
-
field :
|
11
|
+
field :title, _("Title")
|
12
12
|
field :release_name, _("Release name")
|
13
13
|
field :family, _("Family")
|
14
14
|
end
|
@@ -41,56 +41,17 @@ module HammerCLIForeman
|
|
41
41
|
|
42
42
|
|
43
43
|
class CreateCommand < HammerCLIForeman::CreateCommand
|
44
|
-
|
45
|
-
#FIXME: replace with build_options when they are added to the api docs
|
46
|
-
option "--architecture-ids", "ARCH_IDS", _("set associated architectures"),
|
47
|
-
:format => HammerCLI::Options::Normalizers::List.new
|
48
|
-
option "--config-template-ids", "CONFIG_TPL_IDS", _("set associated templates"),
|
49
|
-
:format => HammerCLI::Options::Normalizers::List.new
|
50
|
-
option "--medium-ids", "MEDIUM_IDS", _("set associated installation media"),
|
51
|
-
:format => HammerCLI::Options::Normalizers::List.new
|
52
|
-
option "--ptable-ids", "PTABLE_IDS", _("set associated partition tables"),
|
53
|
-
:format => HammerCLI::Options::Normalizers::List.new
|
54
|
-
|
55
44
|
success_message _("Operating system created")
|
56
45
|
failure_message _("Could not create the operating system")
|
57
46
|
|
58
|
-
def request_params
|
59
|
-
params = super
|
60
|
-
params["operatingsystem"]["architecture_ids"] = option_architecture_ids if option_architecture_ids
|
61
|
-
params["operatingsystem"]["config_template_ids"] = option_config_template_ids if option_config_template_ids
|
62
|
-
params["operatingsystem"]["medium_ids"] = option_medium_ids if option_medium_ids
|
63
|
-
params["operatingsystem"]["ptable_ids"] = option_ptable_ids if option_ptable_ids
|
64
|
-
params
|
65
|
-
end
|
66
|
-
|
67
47
|
build_options
|
68
48
|
end
|
69
49
|
|
70
50
|
|
71
51
|
class UpdateCommand < HammerCLIForeman::UpdateCommand
|
72
|
-
#FIXME: replace with build_options when they are added to the api docs
|
73
|
-
option "--architecture-ids", "ARCH_IDS", _("set associated architectures"),
|
74
|
-
:format => HammerCLI::Options::Normalizers::List.new
|
75
|
-
option "--config-template-ids", "CONFIG_TPL_IDS", _("set associated templates"),
|
76
|
-
:format => HammerCLI::Options::Normalizers::List.new
|
77
|
-
option "--medium-ids", "MEDIUM_IDS", _("set associated installation media"),
|
78
|
-
:format => HammerCLI::Options::Normalizers::List.new
|
79
|
-
option "--ptable-ids", "PTABLE_IDS", _("set associated partition tables"),
|
80
|
-
:format => HammerCLI::Options::Normalizers::List.new
|
81
|
-
|
82
52
|
success_message _("Operating system updated")
|
83
53
|
failure_message _("Could not update the operating system")
|
84
54
|
|
85
|
-
def request_params
|
86
|
-
params = super
|
87
|
-
params["operatingsystem"]["architecture_ids"] = option_architecture_ids if option_architecture_ids
|
88
|
-
params["operatingsystem"]["config_template_ids"] = option_config_template_ids if option_config_template_ids
|
89
|
-
params["operatingsystem"]["medium_ids"] = option_medium_ids if option_medium_ids
|
90
|
-
params["operatingsystem"]["ptable_ids"] = option_ptable_ids if option_ptable_ids
|
91
|
-
params
|
92
|
-
end
|
93
|
-
|
94
55
|
build_options
|
95
56
|
end
|
96
57
|
|
@@ -112,7 +73,7 @@ module HammerCLIForeman
|
|
112
73
|
|
113
74
|
def validate_options
|
114
75
|
super
|
115
|
-
validator.any(:option_operatingsystem_id).required
|
76
|
+
validator.any(:option_operatingsystem_id, :option_operatingsystem_title).required
|
116
77
|
end
|
117
78
|
|
118
79
|
build_options
|
@@ -126,7 +87,7 @@ module HammerCLIForeman
|
|
126
87
|
|
127
88
|
def validate_options
|
128
89
|
super
|
129
|
-
validator.any(:option_operatingsystem_id).required
|
90
|
+
validator.any(:option_operatingsystem_id, :option_operatingsystem_title).required
|
130
91
|
end
|
131
92
|
|
132
93
|
build_options
|
@@ -137,7 +98,7 @@ module HammerCLIForeman
|
|
137
98
|
command_name "set-default-template"
|
138
99
|
resource :os_default_templates
|
139
100
|
|
140
|
-
option "--id", "OS ID", _("operatingsystem id"), :required => true
|
101
|
+
option "--id", "OS ID", _("operatingsystem id"), :required => true, :referenced_resource => 'operatingsystem'
|
141
102
|
option "--config-template-id", "TPL ID", _("config template id to be set"), :required => true
|
142
103
|
|
143
104
|
|
@@ -203,7 +164,7 @@ module HammerCLIForeman
|
|
203
164
|
command_name "delete-default-template"
|
204
165
|
resource :os_default_templates
|
205
166
|
|
206
|
-
option "--id", "OS ID", _("operatingsystem id"), :required => true
|
167
|
+
option "--id", "OS ID", _("operatingsystem id"), :required => true, :referenced_resource => 'operatingsystem'
|
207
168
|
option "--type", "TPL TYPE", _("Type of the config template"), :required => true
|
208
169
|
|
209
170
|
success_message _("Default template deleted")
|
@@ -81,6 +81,11 @@ module HammerCLIForeman
|
|
81
81
|
builders << DependentSearchablesOptionBuilder.new(dep_resource, @searchables)
|
82
82
|
end
|
83
83
|
|
84
|
+
IdArrayParamsFilter.new(:only_required => false).for_action(action).each do |p|
|
85
|
+
resource = HammerCLIForeman.param_to_resource(p.name)
|
86
|
+
builders << DependentSearchablesArrayOptionBuilder.new(resource, @searchables) unless resource.nil?
|
87
|
+
end
|
88
|
+
|
84
89
|
builders
|
85
90
|
end
|
86
91
|
|
@@ -145,6 +150,10 @@ module HammerCLIForeman
|
|
145
150
|
|
146
151
|
protected
|
147
152
|
|
153
|
+
def option(*args)
|
154
|
+
HammerCLI::Apipie::OptionDefinition.new(*args)
|
155
|
+
end
|
156
|
+
|
148
157
|
def description(param_name, action_name)
|
149
158
|
return " " unless @resource.has_action? action_name
|
150
159
|
|
@@ -172,7 +181,8 @@ module HammerCLIForeman
|
|
172
181
|
option(
|
173
182
|
optionamize("--#{s.name}"),
|
174
183
|
s.name.upcase,
|
175
|
-
s.description
|
184
|
+
s.description,
|
185
|
+
:referenced_resource => @resource.singular_name
|
176
186
|
)
|
177
187
|
end
|
178
188
|
end
|
@@ -211,7 +221,8 @@ module HammerCLIForeman
|
|
211
221
|
optionamize("--#{aliased_name}"),
|
212
222
|
"#{aliased_name}_#{first.name}".upcase,
|
213
223
|
first.description || " ",
|
214
|
-
:attribute_name => HammerCLI.option_accessor_name("#{resource_name}_#{first.name}")
|
224
|
+
:attribute_name => HammerCLI.option_accessor_name("#{resource_name}_#{first.name}"),
|
225
|
+
:referenced_resource => resource.singular_name
|
215
226
|
)
|
216
227
|
|
217
228
|
# Other options are named by the resource plus the searchable name
|
@@ -221,7 +232,8 @@ module HammerCLIForeman
|
|
221
232
|
optionamize("--#{aliased_name}-#{s.name}"),
|
222
233
|
"#{aliased_name}_#{s.name}".upcase,
|
223
234
|
s.description || " ",
|
224
|
-
:attribute_name => HammerCLI.option_accessor_name("#{resource_name}_#{s.name}")
|
235
|
+
:attribute_name => HammerCLI.option_accessor_name("#{resource_name}_#{s.name}"),
|
236
|
+
:referenced_resource => resource.singular_name
|
225
237
|
)
|
226
238
|
end
|
227
239
|
end
|
@@ -230,7 +242,8 @@ module HammerCLIForeman
|
|
230
242
|
optionamize("--#{aliased_name}-id"),
|
231
243
|
"#{aliased_name}_id".upcase,
|
232
244
|
description("id", :show),
|
233
|
-
:attribute_name => HammerCLI.option_accessor_name("#{resource_name}_id")
|
245
|
+
:attribute_name => HammerCLI.option_accessor_name("#{resource_name}_id"),
|
246
|
+
:referenced_resource => resource.singular_name
|
234
247
|
)
|
235
248
|
options
|
236
249
|
end
|
@@ -241,6 +254,52 @@ module HammerCLIForeman
|
|
241
254
|
|
242
255
|
end
|
243
256
|
|
257
|
+
|
258
|
+
|
259
|
+
class DependentSearchablesArrayOptionBuilder < DependentSearchablesOptionBuilder
|
260
|
+
|
261
|
+
|
262
|
+
def dependent_options(resource, resource_name_map)
|
263
|
+
options = []
|
264
|
+
searchables = @searchables.for(resource)
|
265
|
+
resource_name = resource.singular_name
|
266
|
+
|
267
|
+
aliased_name = aliased(resource_name, resource_name_map)
|
268
|
+
aliased_plural_name = aliased(resource.name, resource_name_map)
|
269
|
+
|
270
|
+
unless searchables.empty?
|
271
|
+
first = searchables[0]
|
272
|
+
remaining = searchables[1..-1] || []
|
273
|
+
|
274
|
+
# First option is named by the resource
|
275
|
+
# Eg. --organizations with accessor option_organization_names
|
276
|
+
options << option(
|
277
|
+
optionamize("--#{aliased_plural_name}"),
|
278
|
+
"#{aliased_name}_#{first.plural_name}".upcase,
|
279
|
+
" ",
|
280
|
+
:attribute_name => HammerCLI.option_accessor_name("#{resource_name}_#{first.plural_name}"),
|
281
|
+
:format => HammerCLI::Options::Normalizers::List.new,
|
282
|
+
:referenced_resource => resource.singular_name
|
283
|
+
)
|
284
|
+
|
285
|
+
# Other options are named by the resource plus the searchable name
|
286
|
+
# Eg. --organization-labels with accessor option_organization_labels
|
287
|
+
remaining.each do |s|
|
288
|
+
options << option(
|
289
|
+
optionamize("--#{aliased_name}-#{s.plural_name}"),
|
290
|
+
"#{aliased_name}_#{s.plural_name}".upcase,
|
291
|
+
" ",
|
292
|
+
:attribute_name => HammerCLI.option_accessor_name("#{resource_name}_#{s.plural_name}"),
|
293
|
+
:format => HammerCLI::Options::Normalizers::List.new,
|
294
|
+
:referenced_resource => resource.singular_name
|
295
|
+
)
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
options
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
244
303
|
class SearchablesUpdateOptionBuilder < SearchablesAbstractOptionBuilder
|
245
304
|
|
246
305
|
def initialize(resource, searchables)
|
@@ -276,7 +335,7 @@ module HammerCLIForeman
|
|
276
335
|
|
277
336
|
def build(builder_params={})
|
278
337
|
[
|
279
|
-
option("--id", "ID", description("id", :show))
|
338
|
+
option("--id", "ID", description("id", :show), :referenced_resource => @resource.singular_name)
|
280
339
|
]
|
281
340
|
end
|
282
341
|
|