[Question] Optional unordered key/value pairs ?
Hello,
How can I do the following using cliffy ?
--param2=foo --param1=bar --param3
Thanks
Hey @tianalemesle. Cliffy doesn't currently support "options" with associated values like in your example. We only support unlabeled parameters. It's an interesting idea, so I'll think about how we might add support in the future.
Here is what the call would look like with cliffy:
my_command foo bar @param3
Here's an example implementation:
const cli = new CLI()
.addCommand("my_command", {
description: "Do something",
options: [{ label: "param3", description: "Param 3" }],
parameters: ["param1", "param2],
action: (params, options) => {
if (options.param3) {
console.log(`Option param3 was passed`)
return;
}
console.log(params.param1) // foo
console.log(params.param2) // bar
},
Short explanation
In cliffy, "options" are specified using the @ symbol instead of the --. The reason we do this is to allow negative numbers to be passed as parameters.
Yes, I've carfully read the README, and had to use vorpal for now, which is unmaintained :
cli
.command(
'list',
'List hooks'
)
.option('--limit <limit>', 'Limit')
.option('--status <status>', 'Filter by pending/completed/failed status')
.option('--sortBy <sortBy>', 'Sort by creation/post date')
.option('--sortOrder <sortOrder>', 'Sort asc/desc')
.option('--minPostDate <minPostDate>', 'Filter by min post date')
.option('--maxPostDate <maxPostDate>', 'Filter by max post date')
.option('--minCreationDate <minCreationDate>', 'Filter by min creation date')
.option('--maxCreationDate <maxCreationDate>', 'Filter by max creation date')
All those options need to be optional, unordered and associated with values.
For example, @foo=bar @baz="fum qux" would be okay.
Thanks
Yeah. Not fully supported yet. You can do optional parameters however.
Yes, but ordered, which means an optional parameter cannot be specified without specifying the previous optional ones.