Skip to content

Latest commit

 

History

History
24 lines (18 loc) · 540 Bytes

section46.1.md

File metadata and controls

24 lines (18 loc) · 540 Bytes

Section 46.1: Passing action (verb) and values

const options = require("commander");

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

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

options.parse(process.argv);

if (!options.args.length) options.help();

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