Is there a way to overwrite commander js usage information?

607 views Asked by At

I want to completely overwrite usage information from commander js:

Usage: name [options]

Options:
  -V, --version  output the version number
  -h, --help     display help for command

to create my own. However, I cannot find option to do that.

2

There are 2 answers

0
shadowspawn On

From the README: https://github.com/tj/commander.js

The built-in help is formatted using the Help class. You can configure the Help behaviour by modifying data properties and methods using .configureHelp(), or by subclassing using .createHelp() if you prefer.

.usage and .name
These allow you to customise the usage description in the first line of the help.

2
Patrice Thimothee On

Alternatively, a function helpInformation() in Commander returns the help content, which may help to override the whole generated help text.

I am unsure whether it is part of the public API, but it is available in commander v9.4.1 and most likely in other versions.


const showCustom = process.argv.indexOf("--help") >= 0 || process.argv.indexOf("-h") >= 0
if (showCustom)
{
   const content = program.helpInformation();
   console.log(content);
   return ;
}

program.parse();