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

[Question] Optional unordered key/value pairs ? #22

Open
tianalemesle opened this issue Jun 3, 2022 · 5 comments
Open

[Question] Optional unordered key/value pairs ? #22

tianalemesle opened this issue Jun 3, 2022 · 5 comments

Comments

@tianalemesle
Copy link

Hello,

How can I do the following using cliffy ?

--param2=foo --param1=bar --param3

Thanks

@drew-y
Copy link
Owner

drew-y commented Jun 8, 2022

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.

@KaKi87
Copy link

KaKi87 commented Jun 9, 2022

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

@drew-y
Copy link
Owner

drew-y commented Jun 9, 2022

Yeah. Not fully supported yet. You can do optional parameters however.

@KaKi87
Copy link

KaKi87 commented Jun 10, 2022

Yes, but ordered, which means an optional parameter cannot be specified without specifying the previous optional ones.

@KaKi87
Copy link

KaKi87 commented Dec 21, 2022

Hello,
Any news on this ?
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants