Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 69 lines (50 sloc) 1.52 kB
#!/usr/bin/env node
var mingy = require('../lib/mingy')
, Parser = mingy.Parser
, Command = mingy.Command
, argv = require('optimist')
.boolean(['e'])
.argv
// set up parser and commands
var parser = new Parser()
// allow command-line flag to determine whether equation gets shown
parser.env['showEquation'] = argv['e']
parser.addCommand('add')
.set('syntax', [
'add <number:a> <number:b>',
'+ <number:a> <number:b>'
])
.set('logic', function(args, env) {
var output = ''
if (env.showEquation) {
output += args['a'] + " + " + args['b'] + " = "
}
output += args['a'] + args['b']
return output
})
parser.addCommand('subtract')
.set('syntax', [
'subtract <number:a> <number:b>',
'- <number:a> <number:b>'
])
.set('logic', function(args) {
return args['a'] + args['b']
})
parser.addCommand('help')
.set('syntax', ['help'])
.set('logic', function(args, env) {
var output = ''
output += 'Welcome to POWERCALC!\n\n'+
' Usage: calc [options] <command>\n\n'+
' Options:\n'+
' -e show equation\n\n'+
' Commands:\n'+
' "add <number> <number>" to add two numbers\n'+
' "+ <number> <number>" to add two numbers\n'+
' "subtract <number> <number>" to subtract two numbers\n'+
' "- <number> <number>" to subtract two numbers'
return output
})
var output = parser.parseLexemes(argv['_'])
output = output || 'Bad arguments! Try "calc help".'
console.log(output)
Jump to Line
Something went wrong with that request. Please try again.