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

GNU-style triple-dash option (---gnu-style-hidden-option) no longer work in 13.0.0 #2309

Open
wataash opened this issue Jan 9, 2025 · 2 comments

Comments

@wataash
Copy link

wataash commented Jan 9, 2025

In 12.1.0, ---gnu-style-hidden-option was parsed as GnuStyleHiddenOption, but due to the changes in #2270, 13.0.0 now throws an error: Error: invalid Option flags: '---gnu-style-hidden-option'.

import { Command, Option } from "@commander-js/extra-typings";
const program = new Command();

program
  .addOption(new Option("---gnu-style-hidden-option").hideHelp().default(false))
  .action((opts) => {
    console.log(opts.GnuStyleHiddenOption);
    // 12.1.0: true or false
    // 13.0.0: Error: invalid Option flags: '---gnu-style-hidden-option'

    // N.B. @commander-js/extra-typings correctly infers the type of opts as { GnuStyleHiddenOption: boolean; }
    // (even with @commander-js/extra-typings 13.0.0)
  })
  .parse();

/*
$ node /src/program_a/a.js ---gnu-style-hidden-option
/src/program_a/node_modules/commander/lib/option.js:342
    throw new Error(`invalid Option flags: '${flags}'`);
          ^

Error: invalid Option flags: '---gnu-style-hidden-option'
    at splitOptionFlags (/src/program_a/node_modules/commander/lib/option.js:342:11)
    at new Option (/src/program_a/node_modules/commander/lib/option.js:20:25)
    at file:///src/program_a/a.js:10:16
    at ModuleJob.run (node:internal/modules/esm/module_job:271:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:547:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:116:5)

Node.js v22.12.0
*/

Additional context

In GNU programs, triple-hyphen options are used as hidden debugging options that do not appear in the program --help output. (As far as I know, this is not documented anywhere and seems to be a convention within the GNU project. I think it existed in projects other than coreutils, but I'm not sure.)

(I understand this is an unsupported usage, so I think this breaking change is valid. Feel free to close this issue. I just wanted to let you know that this unusual usage existed.)

@shadowspawn
Copy link
Collaborator

shadowspawn commented Jan 9, 2025

Thanks for the report and context. The stricter check on what Option flags are supported is picking up a few variations to consider!

Other variations: #2307 #2270 (comment)

@shadowspawn
Copy link
Collaborator

shadowspawn commented Jan 11, 2025

The upper case start of the option name GnuStyleHiddenOption is a visible clue that Commander is not expecting this format.

From a code search on GitHub, I think this format is currently very rare, and possibly used in error in these hits rather than on purpose: search

Not currently planning to support this format. (Although I was still interested to hear about it!)

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