sindresorhus / meow

🐈 CLI app helper
MIT License
3.53k stars 150 forks source link

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

Closed melusc closed 1 year ago

melusc commented 1 year ago

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 commented 1 year ago

// @bartaz

melusc commented 1 year ago

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 commented 1 year ago

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

https://github.com/sindresorhus/meow/blob/0b075242653d6cd874d779a4e6f04d191bd9c3e3/index.js#L150-L159