-
Notifications
You must be signed in to change notification settings - Fork 2
Command Line Program
JoshRagem edited this page Jun 22, 2013
·
1 revision
Using optimist to make something on the command line:
var QuickConnect = require('qcnode').QuickConnect,
op = require('optimist'),
qc = new QuickConnect
op.usage("Usage: $0 echojoin [-s <joiner>]")
qc.command('help')
.vcf(function(data, qc){
op.showHelp()
return qc.STACK_CONTINUE
})
qc.command('echojoin')
.vcf(function(data,qc){
console.log(data.args.join(data.space))
return qc.STACK_CONTINUE
})
var userArgs = op.options('s', {
alias: 'space',
default: ' '
}).argv,
args = userArgs._
try {
qc.run(args.shift(),{args:args, space:userArgs.space},{})
} catch (error) {
qc.run('help')
}
This works really well. Optimist is very useful but does not run code as a result of the arguments; qcnode runs code but does not parse arguments. Perfect match.