sindresorhus / meow

🐈 CLI app helper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`allowUnknownFlags: false` prevents aliases for `help` and `version`.

melusc opened this issue · comments

commented

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
commented

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

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

@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'};
}
}