Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

83
Visualizações
Avoid commander parser complaining when no arguments are present and just show helpInfo

I'm migrating a package from a much older version of commander (v2.20.3)

program.command(`install [pkg]`)
  .alias(`i`)
  .action(installPackageOrLocal)
  .option(`-S, --save`, `Save to dependencies`)
  .option(`-D, --save-dev`, `Save to devDependencies`)
  .option(`--production`, `Will not install modules listed in devDependencies`)
  .option(`--test`, `Exit with code 1 if package limits like maxPackagesNumber or maxSizeBites exceeded`);

I'd like for the default (when calling the CLI with no arguments at all) to continue being the display of the help and no erring out, but currently it errs with:

.../npm-reflect/node_modules/.pnpm/commander@8.3.0/node_modules/commander/lib/command.js:142 const [, name, args] = nameAndArgs.match(/([^ ]+) (.)/);

I was able to get the mostly desired behavior by adding:

program.command('help', {isDefault: true})
  .action(() => {
    program.help();
  })
  .command(`install [pkg]`)
  // ...

...but this seems to be polluting things in the help by listing a new "help" command. How can I avoid the parser complaining when no arguments are present yet without adding a new command?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

  1. The default behaviour in latest Commander is to display the help if you have subcommands and do not specify a subcommand. Which sounds like what you want! Not sure how you are getting an error, you might want to open a Commander issue for help.

  2. In general, if you want some custom behaviour for no arguments then it may be simple and easy to check yourself before calling parse(). e.g.

if (process.argv.length < 3)
  program.help(); // exits
program.parse(process.argv);
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda