Skip to content

Command Line Program

JoshRagem edited this page Jun 22, 2013 · 1 revision

Command Line Program

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')
}

Notes

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.

Clone this wiki locally