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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | 1x 1x 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x 6x 4x 6x 4x 4x 4x 9x 9x 6x 6x 4x 4x 1x 2x 9x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 10x 10x 6x 6x 4x 4x 4x 4x 6x 6x 6x 6x 4x 4x 4x 2x | const {pipe} = require('./pipe') const parser = (stages = {}, parsers = {}) => { const { argv = [], toOpts = toOpts2, opts = [], toArgs = toArgs2, args = [] } = stages return opt => (processArgv = [], errs = []) => pipe( ...argv, toOpts(opt), ...opts, toArgs(parsers), ...args )({errs, argv: processArgv}) } module.exports = { parser, toArgs2, toOpts2, foo, getOptsFromPath } function toOpts2 (opt) { return pipe( foo(opt) ) } function foo (opt) { return ({errs = [], argv = []} = {}) => { const paths = [[]] return bar(paths, opt, [], argv, errs) } } function bar (paths, opt, opts, argv, errs) { Iif (argv.length === 0) return {errs, opts} const paths2 = uniqPaths(paths) const baz = paths2.reduce( ({opts, argv, paths}, path) => { const opts2 = getOptsFromPath(path, opt) const arg = argv[0] const [indexes, opts3] = optsForArg(opts2, arg) const paths2 = [...paths, ...indexes.map(i => [...path, i])] for (let i = 0; i < opts3.length; i++) { const opt = opts3[i] } return {opts, paths: paths2} }, {opts, argv, paths: []} ) const {opts: opts2, paths: paths3} = baz return {errs: [], opts: []} } function getOptsFromPath (path, opt) { let opts = opt.opts || [] for (let i = 0; i < path.length; i++) { const index = path[i] if (index in opts) { const cmd = opts[index] if (typeof cmd === 'object' && Array.isArray(cmd.opts)) opts = cmd.opts else opts = [] } else opts = [] } return opts } function uniqPaths (paths) { const paths2 = [] for (let i = 0; i < paths.length; i++) { const path = paths[i] Eif (!paths.slice(i + 1).some(pathsEq(path))) { paths2.push(path) } } return paths2 } function pathsEq (path2) { return path1 => { if (path1 === path2) return true if (path1.length !== path2.length) return false for (let i = 0; i < path1.length; i++) { const elem1 = path1[i] const elem2 = path2[i] if (elem1 !== elem2) return false } return true } } function optsForArg (opts, arg) { const indexes = [] const opts2 = [] for (let i = 0; i < opts.length; i++) { const opt = opts[i] if(Array.isArray(opt.args) && opt.args.indexOf(arg) > -1) { indexes.push(i) opts2.push(opt) } } const opts3 = withSameTypesLength(opts2) const indexes2 = [] const opts4 = [] for (let i = 0; i < opts3.length; i++) { const opt = opts3[i] Eif (opt !== null) { indexes2.push(indexes[i]) opts4.push(opt) } } return [indexes, opts4] } function withSameTypesLength (opts) { Iif (opts.length === 0) return opts else { return opts.slice(1).reduce( ([head, ...tail], opt) => ( (typeof head.types === 'undefined' && typeof opt.types === 'undefined') || (Array.isArray(head.types) && Array.isArray(opt.types) && head.types.length === opt.types.length) ? [head, ...tail, opt] : [head, ...tail, null] ), opts.slice(0, 1) ) } } function toArgs2 (parsers) { return ({errs = [], opts = []} = {errs: [], opts: []}) => { return ({errs, args: opts}) } } |