Passing action verb and values

suggest change

This uses commander 9 or later. A command with only options receives the option object in its action callback. Read the root command's flags with program.opts().

const { program } = require("commander");

program
  .option("-v, --verbose", "Be verbose");

program
  .command("convert")
  .alias("c")
  .description("Converts an input file to an output file")
  .option("-i, --in-file <file_name>", "Input file")
  .option("-o, --out-file <file_name>", "Output file")
  .action(doConvert);

program.parse(process.argv);

if (process.argv.length <= 2) program.help();

function doConvert(options) {
  // Do something with options.inFile and options.outFile
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents