All files cli.js

0% Statements 0/7
0% Branches 0/4
100% Functions 0/0
0% Lines 0/7
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                                                                             
 
const cliOptions = require('nopt')(
  { // type check
    file: require('path'),
    'min-time': Number,
    groupBy: ['None', 'Category', 'Subdomain', 'Domain', 'URL', 'EventName'],
    startMark: String,
    endMark: String,
    output: String },
  { // shorthand
    f: ['--file'],
    t: ['--min-time'],
    g: ['--groupBy'],
    s: ['--startMark'],
    e: ['--endMark'],
    o: ['--output'],
    json: ['--output=json']
  }
)
 
 
// if -f (file) option is not given, assume the first CLI argument is the file path
const options = {
  file: cliOptions.file || cliOptions.argv.remain[0],
  minTime: cliOptions['min-time'],    
  groupBy: cliOptions.groupBy,
  startMark: cliOptions.startMark,
  endMark: cliOptions.endMark
}
 
const statsPerDomain = require('./index')
 
if( cliOptions.output === 'json') {
  console.log(statsPerDomain.data(options))
} else {
  console.log('Analyzing', options.file)
  console.log(statsPerDomain.toTableConsole(options))
}