Skip to content

Commit

Permalink
fixes: recognize ncc --version as ncc version and ncc --help as…
Browse files Browse the repository at this point in the history
… ncc help (#1030)

- Fixes #1029
  • Loading branch information
mreis1 authored Jan 24, 2023
1 parent 25f33cc commit d38b619
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,22 @@ function nccError(msg, exitCode = 1) {
throw err;
}

function showHelp() {
nccError(usage, 2)
}

function showVersion() {
process.stdout.write(require("../package.json").version + '\n');
}

async function runCmd (argv, stdout, stderr) {
let args;
try {
args = require("arg")({
"--help": Boolean,
"-h": "--help",
"--version": Boolean,
"-v": "--version",
"--asset-builds": Boolean,
'-a': '--asset-builds',
"--debug": Boolean,
Expand Down Expand Up @@ -164,6 +176,12 @@ async function runCmd (argv, stdout, stderr) {
nccError(e.message + `\n${usage}`, 2);
}

if (args['--help']) {
return showHelp();
} else if (args['--version']) {
return showVersion();
}

if (args._.length === 0)
nccError(`Error: No command specified\n${usage}`, 2);

Expand All @@ -172,6 +190,7 @@ async function runCmd (argv, stdout, stderr) {
const quiet = args["--quiet"];
const statsOutFile = args["--stats-out"];


switch (args._[0]) {
case "cache":
if (args._.length > 2)
Expand Down Expand Up @@ -357,10 +376,11 @@ async function runCmd (argv, stdout, stderr) {
break;

case "help":
nccError(usage, 2);
showHelp();
break;

case "version":
stdout.write(require("../package.json").version + '\n');
showVersion();
break;

default:
Expand Down

0 comments on commit d38b619

Please sign in to comment.