Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: inject yargs and minimist instead of optimist #3449

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 14 additions & 15 deletions lib/cli.js
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