Passing action verb and values
suggest changeThis 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
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents