node.js - Creating CLI using NodeJS - Passing variable to exec linux command -
im trying create simple cli using nodejs , commander.js package.
the purpose of cli touch new file
const program = require('commander'); const exec = require('child_process').exec; program.version('0.0.1') .description('command line interface (cli)'); program.command('make:controller <name>') .description('add new controller called <name>') .action(function (name) { exec("touch name"); }); program.parse(process.argv);
command: make:controller newcontroller
linux: touch newcontroller
how pass in name variable exec() command.
p.s (after created new file want write it)
const program = require('commander'); const exec = require('child_process').exec; program.version('0.0.1') .description('command line interface (cli)'); program.command('make:controller <name>') .description('add new controller called <name>') .action(function (name) { exec("touch " + name);//mind space after touch }); program.parse(process.argv);
Comments
Post a Comment