Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support multiple data flag usage #192

Merged
merged 2 commits into from
Oct 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func WithProcessingModeValue() GetOption {
// WithData adds support for data input
func WithData() Option {
return func(cmd *cobra.Command) *cobra.Command {
cmd.Flags().StringP(FlagDataName, "d", "", "static data to be applied to body. accepts json or shorthand json, i.e. --data 'value1=1,my.nested.value=100'")
cmd.Flags().StringArrayP(FlagDataName, "d", []string{}, "static data to be applied to body. accepts json or shorthand json, i.e. --data 'value1=1,my.nested.value=100'")
return cmd
}
}
Expand Down
19 changes: 19 additions & 0 deletions tests/manual/common/flag_data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,22 @@ tests:
}
}
}

It support multiple data flags:
command: |
c8y devices create --data name=MyDevice --data "subtypes=[linuxA,linuxB]" --data "my.value=1" --data "prop2=false" --dry --dryFormat json |
c8y util show --select body --output json -c=false
exit-code: 0
stdout:
exactly: |
{
"body": {
"c8y_IsDevice": {},
"my": {
"value": 1
},
"name": "MyDevice",
"prop2": false,
"subtypes": ["linuxA", "linuxB"]
}
}
18 changes: 18 additions & 0 deletions tests/manual/template/template_execute.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,21 @@ tests:
stdout:
exactly: |
{"prop1":{"value":1},"prop2":"two"}

It can combine data and template flags:
command: |
c8y template execute \
--template "{name: 'testdevice'}" \
--data "my.value=1" \
--data "prop2=false" \
--output json -c=false
exit-code: 0
stdout:
exactly: |
{
"my": {
"value": 1
},
"name": "testdevice",
"prop2": false
}