From 0215b626811e115d8eca530226ad59f9fcb0ac55 Mon Sep 17 00:00:00 2001 From: Devansu Date: Mon, 25 Apr 2022 08:26:27 +0000 Subject: [PATCH 1/6] feat(cli): add alias for swa cli global options --- src/cli/index.ts | 4 ++-- src/core/utils/options.spec.ts | 22 +++++++++++++++++++++- src/core/utils/options.ts | 2 +- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/cli/index.ts b/src/cli/index.ts index 372e9f054..83e1b1ab2 100755 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -59,7 +59,7 @@ export async function run(argv?: string[]) { // SWA CLI common configuration options .addOption( - new Option("--verbose [prefix]", "enable verbose output. Values are: silly,info,log,silent") + new Option("-V, --verbose [prefix]", "enable verbose output. Values are: silly,info,log,silent") .preset(DEFAULT_CONFIG.verbose) .default(DEFAULT_CONFIG.verbose) ) @@ -74,7 +74,7 @@ export async function run(argv?: string[]) { "after", ` Type "swa" to get started and deploy your project. - + Documentation: https://aka.ms/swa/cli-local-development ` diff --git a/src/core/utils/options.spec.ts b/src/core/utils/options.spec.ts index 8633cf470..44281fe98 100644 --- a/src/core/utils/options.spec.ts +++ b/src/core/utils/options.spec.ts @@ -2,7 +2,8 @@ import { Command } from "commander"; import mockFs from "mock-fs"; import { swaCliConfigFilename } from "./cli-config"; import { parsePort } from "./net"; -import { configureOptions } from "./options"; +import { configureOptions, getUserOptions } from "./options"; +import { DEFAULT_CONFIG } from "../../config"; describe("configureOptions()", () => { afterEach(() => { @@ -91,3 +92,22 @@ describe("configureOptions()", () => { }); }); }); + +describe("Testing aliases for each of the commands and their options", () => { + it("should return appropriate user cli options for the alias commands for global options", async () => { + const command = await new Command() + .name("swa") + .option("-V, --verbose [prefix]", "", DEFAULT_CONFIG.verbose) + .option("-c, --config ", "") + .option("-g, --print-config", "", false) + .option("-w, --swa-config-location ", "") + .parseAsync(["node", "swa", "-V", "log", "-c", `../${swaCliConfigFilename}`, "-g", "-w", `${DEFAULT_CONFIG.swaConfigLocation}`]); + + expect(getUserOptions(command)).toStrictEqual({ + verbose: "log", + config: `../${swaCliConfigFilename}`, + printConfig: true, + swaConfigLocation: DEFAULT_CONFIG.swaConfigLocation, + }); + }); +}); diff --git a/src/core/utils/options.ts b/src/core/utils/options.ts index 69e443287..673c62381 100644 --- a/src/core/utils/options.ts +++ b/src/core/utils/options.ts @@ -57,7 +57,7 @@ function setLogLevel(verbosity: string | undefined) { } } -function getUserOptions(command: Command) { +export function getUserOptions(command: Command) { const userOptions: OptionValues = {}; const options = command.optsWithGlobals(); From dd402552007cf294b2376ee534b2da36c7ce219b Mon Sep 17 00:00:00 2001 From: Devansu Date: Wed, 27 Apr 2022 15:30:35 +0000 Subject: [PATCH 2/6] feat(cli): add alias for swa cli start options --- src/cli/commands/start.ts | 8 ++--- src/core/utils/options.spec.ts | 65 ++++++++++++++++++++++++++++++++-- 2 files changed, 66 insertions(+), 7 deletions(-) diff --git a/src/cli/commands/start.ts b/src/cli/commands/start.ts index 4e3f9eb77..dfff858fc 100644 --- a/src/cli/commands/start.ts +++ b/src/cli/commands/start.ts @@ -41,10 +41,10 @@ export default function registerCommand(program: Command) { .option("--host ", "the host address to use for the CLI dev server", DEFAULT_CONFIG.host) .option("--port ", "the port value to use for the CLI dev server", parsePort, DEFAULT_CONFIG.port) - .option("--ssl", "serve the front-end application and API over HTTPS", DEFAULT_CONFIG.ssl) - .option("--ssl-cert ", "the SSL certificate (.crt) to use when enabling HTTPS", DEFAULT_CONFIG.sslCert) - .option("--ssl-key ", "the SSL key (.key) to use when enabling HTTPS", DEFAULT_CONFIG.sslKey) - .option("--run ", "run a custom shell command or script file at startup", DEFAULT_CONFIG.run) + .option("-s, --ssl", "serve the front-end application and API over HTTPS", DEFAULT_CONFIG.ssl) + .option("-e, --ssl-cert ", "the SSL certificate (.crt) to use when enabling HTTPS", DEFAULT_CONFIG.sslCert) + .option("-k, --ssl-key ", "the SSL key (.key) to use when enabling HTTPS", DEFAULT_CONFIG.sslKey) + .option("-r, --run ", "run a custom shell command or script file at startup", DEFAULT_CONFIG.run) .option( "--devserver-timeout