All files / bin ncm-cli.js

80.88% Statements 55/68
50% Branches 3/6
50% Functions 1/2
80.88% Lines 55/68

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 6927x 27x 27x 27x         27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x     27x 27x 27x     27x 27x       27x 27x 27x 27x 27x 27x 27x     27x 27x  
#!/usr/bin/env node
 
'use strict'
 
function handleError (err) {
  console.error(err)
  process.exit(1)
}
 
process.on('unhandledRejection', handleError)
 
const parseArgs = require('minimist')
const pkg = require('../package.json')
 
const commands = {
  config: require('../commands/config'),
  help: require('../commands/help'),
  i: require('../commands/install'),
  install: require('../commands/install'),
  orgs: require('../commands/orgs'),
  whitelist: require('../commands/whitelist'),
  signin: require('../commands/signin'),
  signout: require('../commands/signout'),
  report: require('../commands/report'),
  details: require('../commands/details')
}
 
async function main () {
  const argv = parseArgs(process.argv.slice(2), {
    alias: {
      dir: 'd',
      github: 'g',
      google: 'G',
      compliance: 'c',
      security: 's',
      help: 'h',
      long: 'l',
      org: 'O',
      report: 'r',
      version: 'v',
      json: 'j'
    }
  })
 
  if (argv.dir && typeof argv.dir !== 'string') {
    handleError('ERR_INVALID_ARG_TYPE: --dir or -d must to be a string')
  }
 
  let [command = 'help', ...subargs] = argv._
  if (!Object.keys(commands).includes(command)) {
    command = 'help'
  }
 
  if (argv.version) {
    console.log(pkg.version)
    return
  }
 
  await commands[command](argv, ...subargs)
}
 
// invoke main
if (require.main === module) {
  main().catch(err => {
    console.error(err)
    process.exitCode = 1
  })
}