In a go-c8y-cli extension I would like to use a parameter active
with true/false and model this as shown below.
When I invoke the code completion it does not offer the boolean values for completion.
How can I change this?
- name: activation
description: Activate/ deactivate mapping
descriptionLong: Activate/ deactivate mapping
method: POST
path: service/dynamic-mapping-service/operation
body:
- name: id
<<: *type-mapping
property: parameter.id
description: Id of the mapping
type: id[]
pipeline: true
- name: active
property: parameter.active
description: State of the mapping
type: boolean
bodyTemplates:
- type: jsonnet
template: "{operation: 'ACTIVATE_MAPPING'}"
Typically boolean
types don’t accept a value, like so --activate
.
The presence of the --activate
flags tells the cmd parser to set to to true
. You can explicitly set a value using the syntax, --activate=false
, however since you’re looking for tab completion here, I would suggest just creating two different commands, one to activate a mapping and another to deactivate it,
For example:
- name: activate
description: Activate a mapping
descriptionLong: Activate mapping
method: POST
path: service/dynamic-mapping-service/operation
body:
- name: id
property: parameter.id
description: Id of the mapping
type: id[]
bodyTemplates:
- type: jsonnet
template: "{operation: 'ACTIVATE_MAPPING', parameter: {active: true}}"
- name: deactivate
description: Deactivate a mapping
descriptionLong: Deactivate mapping
method: POST
path: service/dynamic-mapping-service/operation
body:
- name: id
property: parameter.id
description: Id of the mapping
type: id[]
bodyTemplates:
- type: jsonnet
template: "{operation: 'ACTIVATE_MAPPING', parameter: {active: false}}"
This would make for a nicer user experience (imo):
c8y yourplugin mapper activate --id 1234
c8y yourplugin mapper deactivate --id 1234
In comparison, the example snippet that you posted would have “activate” or “activation” in both the command and the flag name. The naming (and focus on activation) might make it harder for users to discover.
c8y yourplugin mapper activation --id 1234 --active false
However, the use-case makes sense, so I’ve added a new type called booleanValue
which is a boolean like flag which accepts a value of true/false (with tab completion).
It is available in go-c8y-cli v2.44.0
1 Like