Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | const combine = require('./src/dsl/fp/combine') const option = require('./src/dsl/fp/option') const parser = require('./src/dsl/fp/parser') const pipe = require('./src/dsl/fp/pipe') 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']) ] }) ] }) ] //console.log('opts', JSON.stringify(opts, null, 2)) const options = combine(...opts.map(option)) //console.log('options', JSON.stringify(options, null, 2)) const mergeArgs = require('./src/parser/mergeArgs') const parseArgs = require('./src/parser/parseArgs') const splitShortOptions = require('./src/parser/splitShortOptions') const cast = require('./src/parser/cast') const validate = require('./src/parser/validate') const argv = process.argv.slice(2) const preprocess = option => pipe(cast(option), validate(option)) function fooParser (options) { return parser( splitShortOptions, parseArgs(preprocess)(options), mergeArgs(fooParser) )(options) } const parse = fooParser(options) console.log('parse', JSON.stringify( parse({argv}), null, 2 )) const questionCmd = string('question', ['--question']) const answerCmd = number('answer', ['--answer', '-a'], {only: [42]}) const answerStrCmd = string('answerStr', ['--answer', '-a']) const questionOpt = option(questionCmd) const answerOpt = option(answerCmd) const answerStrOpt = option(answerStrCmd) const combinedOpt = combine(questionOpt, answerOpt, answerStrOpt) const deepThought = options => parser( splitShortOptions, parseArgs(preprocess)(options), mergeArgs() )(options) const parse2 = deepThought(combinedOpt) console.log('parse2', JSON.stringify( parse2({argv}), null, 2 )) |