Actions
Bug #26120
closedInsufficient parsing capabilities of complex list type options
Difficulty:
Triaged:
No
Pull request:
Team Backlog:
Description
It is not possible to parse complex parameters of type list. E.g.
hammer os create --architectures amd64,i386 --description "Windows 7 EN (2019-01)" --major 6 --minor 1.7601 --family Windows --partition-tables Empty --password-hash SHA256 --provisioning-templates winpe_clone,winpe_finish,winpe_pxelinux_boot_clone,winpe_unattend_template --name Windows7EM2019-01 --os-parameters-attributes="test=1,other=2" Error: ApipieBindings::InvalidArgumentTypesError: operatingsystem[os_parameters_attributes][0] - Hash was expected, operatingsystem[os_parameters_attributes][1] - Hash was expected
The field is defined as a list of hashes in the API
param :os_parameters_attributes, Array, :desc => N_("Array of parameters") do  param :name, String, :desc => N_("Name of the parameter"), :required => true param :value, String, :desc => N_("Parameter value"), :required => true end
Updated by Martin Bacovsky over 5 years ago
At the very least we should allow to use JSON to provide the value
--os-parameters-attributes="[{\"name\":\"test\", \"value\":1}]"
That possibility should be mentioned in the help. We may be able to construct and example based on the param description.
--os-parameters-attributes OS_PARAMETERS_ATTRIBUTES Array of parameters Comma separated list of values. Values containing comma should be quoted or escaped with backslash
Is really hard to use without consulting the API docs.
We may think of something like following for the List normalizer to allow the JSON input.
def format(val) - (val.is_a?(String) && !val.empty?) ? HammerCLI::CSVParser.new.parse(val) : [] + return [] unless val.is_a?(String) && !val.empty? + begin + formatter = JSONInput.new + formatter.format(val) + rescue ArgumentError + HammerCLI::CSVParser.new.parse(val) + end end
Updated by Martin Bacovsky over 5 years ago
- Related to Bug #20348: Hammer Does Not Consistently Escape Quotes When Assigning JSON To A Host Parameter. added
Updated by Oleh Fedorenko over 5 years ago
- Status changed from New to Assigned
- Assignee set to Oleh Fedorenko
Updated by The Foreman Bot over 5 years ago
- Status changed from Assigned to Ready For Testing
- Pull request https://github.com/theforeman/hammer-cli/pull/298 added
Updated by Oleh Fedorenko over 5 years ago
- Status changed from Ready For Testing to Closed
Applied in changeset 494ae8e3db821d36b0db677a0e4df9bf97558129.
Updated by Martin Bacovsky over 5 years ago
- Fixed in Releases hammer-cli-0.17.0 added
Actions