pxi-args
Version:
A command-line arguments parser for pxi (pixie), the small, fast, and magical command-line data processor
45 lines (40 loc) • 1.37 kB
JavaScript
const parser = require('./src/dsl/fp/parser')
const toArgs = require('./src/parser/toArgs')
const toOpts = require('./src/parser/toOpts')
const splitShortOptions = require('./src/parser/argv/splitShortOptions')
const cast = require('./src/parser/opts/cast')
const restrictToOnly = require('./src/parser/opts/restrictToOnly')
function fooParser (opts) {
return parser({
argv: [splitShortOptions],
toOpts,
opts: [cast, restrictToOnly],
toArgs: toArgs(fooParser),
args: []
})(opts)
}
const {array, number, string, bool, flag, command} = require('./src/dsl/fp/types')
const numStr = array(['number', 'string'])
const opts = [
number('chunker', ['--chunker', '-c'], {only: [42]}),
string('applier', ['--applier', '-a']),
numStr('numStr', ['--num-str', '-n']),
flag('verbose', ['--verbose', '-v']),
bool('truFal', ['--tru-fal', '-t']),
command('strlist', ['--strlist', '-s']),
string('noMinus', ['noMinus']),
command('command', ['command'], {
opts: [
{key: 'foo', args: ['--foo'], types: ['number']},
flag('v', ['-v']),
command('init', ['init'], {
opts: [
string('sub', ['--sub'])
]
})
]
})
]
const argv = process.argv.slice(2)
const res = fooParser(opts)({argv})
console.log('fooParser', JSON.stringify(res, null, 2))