From 2ddb47ae4ce49a52d0148133c1b28a9bfdb253fd Mon Sep 17 00:00:00 2001 From: Ramon Brullo Date: Tue, 17 Sep 2024 16:01:41 +0200 Subject: [PATCH] extract options --- src/cli/cmd-add.ts | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/cli/cmd-add.ts b/src/cli/cmd-add.ts index 0e8474d6..7ba574ec 100644 --- a/src/cli/cmd-add.ts +++ b/src/cli/cmd-add.ts @@ -1,4 +1,4 @@ -import { Argument, Command } from "@commander-js/extra-typings"; +import { Argument, Command, Option } from "@commander-js/extra-typings"; import { Logger } from "npmlog"; import { addDependenciesUsing } from "../app/add-dependencies"; import { determineEditorVersionUsing } from "../app/determine-editor-version"; @@ -27,6 +27,16 @@ const otherPkgsArg = new Argument( "References to additional packages that should be added" ).argParser(eachValue(mustBePackageReference)); +const addTestableOpt = new Option( + "-t, --test", + "add package as testable" +).default(false); + +const forceOpt = new Option( + "-f, --force", + "force add package if missing deps or editor version is not qualified" +).default(false); + /** * Makes the `openupm add` cli command with the given dependencies. * @param checkUrlExists IO function to check whether a url exists. @@ -46,14 +56,11 @@ export function makeAddCmd( debugLog: DebugLog ) { return new Command("add") + .aliases(["install", "i"]) .addArgument(pkgArg) .addArgument(otherPkgsArg) - .aliases(["install", "i"]) - .option("-t, --test", "add package as testable") - .option( - "-f, --force", - "force add package if missing deps or editor version is not qualified" - ) + .addOption(addTestableOpt) + .addOption(forceOpt) .description( `add package to manifest json openupm add [otherPkgs...] @@ -111,8 +118,8 @@ openupm add @ [otherPkgs...]` typeof editorVersion === "string" ? null : editorVersion, primaryRegistry, env.upstream, - addOptions.force === true, - addOptions.test === true, + addOptions.force, + addOptions.test, pkgs );