Skip to content

Commit

Permalink
Merge cf651d9 into b8b2ed8
Browse files Browse the repository at this point in the history
  • Loading branch information
akkumar authored Mar 20, 2020
2 parents b8b2ed8 + cf651d9 commit 5d347eb
Show file tree
Hide file tree
Showing 4 changed files with 2,957 additions and 2,368 deletions.
29 changes: 14 additions & 15 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

const path = require('path')
const assert = require('assert')
const optimist = require('optimist')
const yargs = require('yargs')
const minimist = require('minimist')
const fs = require('graceful-fs')

const Server = require('./server')
Expand All @@ -11,7 +12,7 @@ const constant = require('./constants')

function processArgs (argv, options, fs, path) {
if (argv.help) {
console.log(optimist.help())
console.log(yargs.help())
process.exit(0)
}

Expand Down Expand Up @@ -147,12 +148,11 @@ function parseClientArgs (argv) {
// return only args that occur before `--`
function argsBeforeDoubleDash (argv) {
const idx = argv.indexOf('--')

return idx === -1 ? argv : argv.slice(0, idx)
}

function describeShared () {
optimist
yargs
.usage('Karma - Spectacular Test Runner for JavaScript.\n\n' +
'Usage:\n' +
' $0 <command>\n\n' +
Expand All @@ -167,7 +167,7 @@ function describeShared () {
}

function describeInit () {
optimist
yargs
.usage('Karma - Spectacular Test Runner for JavaScript.\n\n' +
'INIT - Initialize a config file.\n\n' +
'Usage:\n' +
Expand All @@ -179,7 +179,7 @@ function describeInit () {
}

function describeStart () {
optimist
yargs
.usage('Karma - Spectacular Test Runner for JavaScript.\n\n' +
'START - Start the server / do a single run.\n\n' +
'Usage:\n' +
Expand All @@ -205,7 +205,7 @@ function describeStart () {
}

function describeRun () {
optimist
yargs
.usage('Karma - Spectacular Test Runner for JavaScript.\n\n' +
'RUN - Run the tests (requires running server).\n\n' +
'Usage:\n' +
Expand All @@ -221,7 +221,7 @@ function describeRun () {
}

function describeStop () {
optimist
yargs
.usage('Karma - Spectacular Test Runner for JavaScript.\n\n' +
'STOP - Stop the server (requires running server).\n\n' +
'Usage:\n' +
Expand All @@ -232,7 +232,7 @@ function describeStop () {
}

function describeCompletion () {
optimist
yargs
.usage('Karma - Spectacular Test Runner for JavaScript.\n\n' +
'COMPLETION - Bash/ZSH completion for karma.\n\n' +
'Installation:\n' +
Expand All @@ -245,11 +245,11 @@ function printRunnerProgress (data) {
}

exports.process = function () {
const argv = optimist.parse(argsBeforeDoubleDash(process.argv.slice(2)))
const argv = minimist(argsBeforeDoubleDash(process.argv.slice(2)))
const options = {
cmd: argv._.shift()
}

const clientArgs = parseClientArgs(process.argv)
switch (options.cmd) {
case 'start':
describeStart()
Expand All @@ -275,16 +275,15 @@ exports.process = function () {
default:
describeShared()
if (!options.cmd) {
processArgs(argv, options, fs, path)
processArgs(yargs.parse(clientArgs), options, fs, path)
console.error('Command not specified.')
} else {
console.error('Unknown command "' + options.cmd + '".')
}
optimist.showHelp()
yargs.showHelp()
process.exit(1)
}

return processArgs(argv, options, fs, path)
return processArgs(yargs.parse(clientArgs), options, fs, path)
}

exports.run = function () {
Expand Down
Loading

0 comments on commit 5d347eb

Please sign in to comment.