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

Convert kebab-case flags to camelCase #68

Open
elliot-nelson opened this issue May 26, 2020 · 2 comments
Open

Convert kebab-case flags to camelCase #68

elliot-nelson opened this issue May 26, 2020 · 2 comments

Comments

@elliot-nelson
Copy link
Member

This difference between commander and yargs and sywac is actually the difference I noticed most when converting some prior CLIs - I had some programs with many (100?) flags, and ended up writing wrappers to convert parameter names instead of renaming them.

What do you think about supporting this use case? I could see three viable paths:

  1. Breaking change: start converting all kebab to camel. Breaks existing programs (potentially).

  2. Add a boolean option defaulting to false for auto converting. Suffers a little from "yet another option", but gives the same behavior for essentially free.

  3. Support more generically - some kind of "flag conversion" or "flag formatting" option. Or maybe even takes a full argv and allows you to define a key converter? This maybe suffers from "yet another option" AND "how the hell does it work".

Interested in your thoughts and how hot/cold you'd be for support for this feature.

@nexdrew
Copy link
Member

nexdrew commented May 28, 2020

I'm honestly not a big fan of doing these types of conversions in sywac, but I'm not opposed to the 2nd option if it will make the migration from commander/yargs to sywac easier for folks.

Let's give it a shot.

@elliot-nelson
Copy link
Member Author

Maybe there's a more "sywacky" way to support it?

If the command line flag is --reset-all, but the developer would prefer to write resetAll, maybe we should be suggesting:

sywac
    .boolean('--reset-all', { desc: 'Reset them all', aliases: 'resetAll' })

This gives you exactly what you had with yargs, with the downside that you need to specify it on every line (a bummer if there are many options). It also lets the user actually use that alias which I guess in very rare cases might not be desirable.

(I'm waffling because I think your inclination not to follow the path of yargs, where the options just grew and grew and grew and included complex boolean statements about what params are required when etc., isn't the right path for sywac.)

Another option:

sywac
    .boolean('--reset-all', { desc: 'Reset them all' })
    .check(argv => {
        Object.keys(argv).forEach(key => {
            argv[key.replace(/-./g, str => str[1].toUpperCase())] = argv[key]
        })
    })

Maybe the "problem" could be solved just by suggesting this snippet in some kind of "converting to sywac" guide in the website?

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

2 participants