All files / src/old/toArgs index.js

100% Statements 14/14
75% Branches 6/8
100% Functions 6/6
100% Lines 13/13

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 513x 3x 3x   68x   3x         26x 26x                 26x                           42x 42x 42x 42x   42x                    
const {convertNonCommands} = require('./convertNonCommands')
const {convertCommands}    = require('./convertCommands')
const {setDefaultValues}   = require('./setDefaultValues')
 
const toArgs = (parsers, mode) => (mode === 'async' ? toArgsAsync : toArgsSync)(parsers)
 
module.exports = {
  toArgs
}
 
function toArgsAsync (parsers) {
  return ({errs = [], opts = []} = {}) => (
    Promise.all([
      convertNonCommands({opts}),
      convertCommands(parsers, 'async')({opts}),
      setDefaultValues({opts})
    ]).then(
      ([
        {errs: errs2, args: args2},
        {errs: errs3, args: args3},
        {errs: errs4, args: args4}
      ]) => ({
        errs: [...errs, ...errs2, ...errs3, ...errs4],
        args: {
          ...args4,
          ...args3,
          ...args2,
          _: [...args2._, ...args3._]
        }
      })
    )
  )
}
 
function toArgsSync (parsers) {
  return ({errs = [], opts = []} = {}) => {
    const {errs: errs2, args: args2} = convertNonCommands({errs, opts})
    const {errs: errs3, args: args3} = convertCommands(parsers, 'sync')({errs: errs2, opts})
    const {errs: errs4, args: args4} = setDefaultValues({errs: errs3, opts})
  
    return {
      errs: errs4,
      args: {
        ...args4,
        ...args3,
        ...args2,
        _: [...args2._, ...args3._]
      }
    }
  }
}