From 5d54d8c20927c5dfabacc128d1cee036a7cf6fb5 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Thu, 9 May 2024 23:13:48 +0530 Subject: [PATCH] fix(cli): disallow unknown options (#1079) * display choices for various options * update incorrect types Note: this prevents people/AI from using v3 options in v4 cli --- README.md | 2 -- src/cli.js | 11 +++++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e16f5eed2..c7821b99b 100644 --- a/README.md +++ b/README.md @@ -303,7 +303,6 @@ nwbuild({ ### Chores -- chore(cli): migrate from `yargs` to `commander` - chore(get): verify sha checksum for downloads - chore: annotate file paths as `fs.PathLike` instead of `string`. - chore(bld): factor out core build step @@ -314,7 +313,6 @@ nwbuild({ - chore(bld): factor out compressing - chore(bld): factor out managed manifest - chore(bld): move `.desktop` entry file logic to `create-desktop-shortcuts` package -- chore(util): factor out file paths as constant variables ## FAQ diff --git a/src/cli.js b/src/cli.js index 1189a7840..d478f16ef 100755 --- a/src/cli.js +++ b/src/cli.js @@ -12,7 +12,8 @@ const cli = yargs(yargs_helpers.hideBin(process.argv)) .command("[srcDir] [options]") .option("mode", { type: "string", - description: "`run` or `build` application", + description: "`get`, `run` or `build` application", + choices: ["get", "run", "build"] }) .option("version", { type: "string", @@ -21,14 +22,17 @@ const cli = yargs(yargs_helpers.hideBin(process.argv)) .option("flavor", { type: "string", description: "NW.js build flavor", + choices: ["normal", "sdk"] }) .option("platform", { type: "string", description: "NW.js supported platform", + choices: ["linux", "osx", "win"] }) .option("arch", { type: "string", description: "NW.js supported architecture", + choices: ["ia32", "x64", "arm64"] }) .option("outDir", { type: "string", @@ -61,15 +65,18 @@ const cli = yargs(yargs_helpers.hideBin(process.argv)) .option("zip", { type: "string", description: "Flag to enable/disable compression", + choices: ["zip", "tar", "tgz"] }) .option("ffmpeg", { - type: "string", + type: "boolean", description: "Flag to enable/disable downloading community ffmpeg", }) .option("logLevel", { type: "string", description: "Specify log level", + choices: ["error", "warn", "info", "debug"] }) + .strictOptions() .parse(); nwbuild({