Reputation: 679
I'm trying to pass an option to a command that I created with commander.js...
program
.command('init [options]')
.description('scaffold the project')
.option('-b, --build', 'add "build" folder with subfolders')
.action(function(){
if(program.build) {
mkdirp("build/")
}
});
program.parse(process.argv);
...where if the -b
flag is passed to init
, the npm mkdirp
module creates a "build" directory. Sadly, I can't get it working...any idea?
Upvotes: 0
Views: 517
Reputation: 1591
change program.build to this.build inside the function passed to .action()
program
.command('init [options]')
.description('scaffold the project')
.option('-b, --build', 'add "build" folder with subfolders')
.action(function(){
if(this.build) {
mkdirp("build/")
}
});
program.parse(process.argv);
Upvotes: 2