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

fixes: recognize ncc --version as ncc version and ncc --help as ncc help #1030

Merged
merged 1 commit into from
Jan 24, 2023
Merged
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
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