Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

allowUnknownFlags: false prevents aliases for help and version. #216

Closed
melusc opened this issue Oct 2, 2022 · 3 comments · Fixed by #217
Closed

allowUnknownFlags: false prevents aliases for help and version. #216

melusc opened this issue Oct 2, 2022 · 3 comments · Fixed by #217

Comments

@melusc
Copy link

melusc commented Oct 2, 2022

When setting allowUnknownFlags to false it now overrides the options for the help and version flags. As seen here https://github.com/sindresorhus/meow/pull/215/files#diff-e727e4bdf3657fd1d798edcd6b099d6e092f8573cba266154583a746bba0f346R150-R160 and released in v10.1.4.

I have something like this to allow -h for --help and -v for --version

meow(
	`...`,
	{		
		importMeta: import.meta,
		flags: {
			help: {
				alias: 'h',
				type: 'boolean',
			},
			version: {
				alias: 'v',
				type: 'boolean',
			},
		},
		allowUnknownFlags: false,
	},
)

but now -h and -v are treated as unknown flags.

$ node ./dist/index.js -v
Unknown flag
-v
@sindresorhus
Copy link
Owner

// @bartaz

@melusc
Copy link
Author

melusc commented Oct 2, 2022

I'm not familiar with the code but I was thinking something like

parserOptions.help = {...parserOptions.help, type: 'boolean'};
// or
parserOptions.help ??= {type: 'boolean'};

@bartaz
Copy link
Contributor

bartaz commented Oct 2, 2022

@melusc Yes, in lines below instead of overriding help and version the options passed as argument should be used if available:

meow/index.js

Lines 150 to 159 in 0b07524

// Add --help and --version to known flags if autoHelp or autoVersion are set
if (!options.allowUnknownFlags) {
if (options.autoHelp) {
parserOptions.help = {type: 'boolean'};
}
if (options.autoVersion) {
parserOptions.version = {type: 'boolean'};
}
}

bartaz added a commit to bartaz/meow that referenced this issue Oct 3, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants