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

allowUnknownFlags option and camel case #178

Open
ozum opened this issue Feb 25, 2021 · 5 comments
Open

allowUnknownFlags option and camel case #178

ozum opened this issue Feb 25, 2021 · 5 comments

Comments

@ozum
Copy link

ozum commented Feb 25, 2021

Hi,

Thanks for the library and the great effort.

I need help with an issue:

When I set allowUnknownFlags to false, camel-case flags are reported as unknown flag. However, when I set allowUnknownFlags to true, both camel-cased and dash-cased flags populate the same camel case key (e.g. out-dir and outDir result with { flags: outDir: "xxx" }).

I expected when allowUnknownFlags is true, both types of flags are allowed, because dash cased flags are already converted to camel case in the result object.

Please see examples below:

allowUnknownFlags: false with camel-case flag

const flags = { outDir: { type: "string", desc: "Some desc." } };
const result = meow("some help",  { flags, allowUnknownFlags: false });
console.log(result.flags);

Command: $ cmd --outDir models
Result: Unknown flag --outDir
Expected: { outDir: "models" }

allowUnknownFlags: true

const flags = { outDir: { type: "string", desc: "Some desc." } };
const result = meow("some help",  { flags, allowUnknownFlags: true });
console.log(result.flags);

Command: $ cmd --outDir models
Result: { outDir: "models" }

Command: $ cmd --out-dir models
Result: { outDir: "models" }

Kind Regards,

@sindresorhus
Copy link
Owner

// @weareoutman

@weareoutman
Copy link
Contributor

weareoutman commented Feb 28, 2021

I'll look at this later. And I also noticed there is a problem when passing --help or --version (which are builtin flags) with allowUnknownFlags: true.

@weareoutman
Copy link
Contributor

@ozum There is currently a workaround to fix this, set an alias for flags.outDir, such as:

const flags = { outDir: { type: "string", alias: "o" } };

Or set the alias to "outDir" or "out-dir" instead of "o" if you think which one makes sense.

The related issue is yargs/yargs-parser#359. I suggest to wait for responses of this issue from yargs-parser, before doing fixes in meow.

@ozum
Copy link
Author

ozum commented Mar 7, 2021

@weareoutman thanks for the effort and for providing a workaround. It helps a lot.

Only a camel-case key with a kebab-key alias works for me.

const flags = { outDir: { type: "string", alias: "out-dir" } };

ozum added a commit to ozum/meow-helper that referenced this issue Mar 7, 2021
Camel-case flags was not working as expected. See: sindresorhus/meow#178
@tommy-mitchell
Copy link
Contributor

Multiple aliases will be supported in the next release, so there will be a workaround with less tradeoffs:

const flags = { outDir: { type: "string", aliases: ["out-dir"], shortFlag: "o" } };

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

4 participants