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

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -