From 94711e59b9311f472581d6bd4d38a8ea2cc020af Mon Sep 17 00:00:00 2001 From: Ramon Brullo Date: Fri, 1 Nov 2024 19:21:55 +0100 Subject: [PATCH] add cmd --- src/cli/cmd-add.ts | 147 +++++++++++++++++++++++---------------------- 1 file changed, 75 insertions(+), 72 deletions(-) diff --git a/src/cli/cmd-add.ts b/src/cli/cmd-add.ts index c57b0200..8c14a791 100644 --- a/src/cli/cmd-add.ts +++ b/src/cli/cmd-add.ts @@ -22,14 +22,9 @@ import { upstreamOpt } from "./opt-upstream"; import { workDirOpt } from "./opt-wd"; import { mustBePackageSpec } from "./validators"; -const packageSpecArg = new Argument( - "", +const packageSpecsArg = new Argument( + "[...]", "Reference to the package that should be added" -).argParser(mustBePackageSpec); - -const otherPackageSpecsArg = new Argument( - "[otherPkgs...]", - "References to additional packages that should be added" ).argParser(eachValue(mustBePackageSpec)); const addTestableOpt = new Option( @@ -82,83 +77,91 @@ export function makeAddCmd( ); return new Command("add") - .aliases(["install", "i"]) - .addArgument(packageSpecArg) - .addArgument(otherPackageSpecsArg) + .aliases([ + "ad", + "i", + "in", + "ins", + "inst", + "insta", + "instal", + "isnt", + "isnta", + "isntal", + "isntall", + "install", + ]) + .addArgument(packageSpecsArg) .addOption(addTestableOpt) .addOption(forceOpt) .addOption(primaryRegistriesUrlOpt) .addOption(workDirOpt) .addOption(systemUserOpt) .addOption(upstreamOpt) + .summary("add a dependency to the project") .description( - `add package to manifest json -openupm add [otherPkgs...] -openupm add @ [otherPkgs...]` + `Add a dependency to the project as well as all indirect dependencies. +openupm add com.some.package@latest +openupm add com.some.package@1.2.3` ) .action( - withErrorLogger( - log, - async function (packageSpec, otherPackageSpecs, options) { - const packageSpecs = [packageSpec].concat(otherPackageSpecs); - - const projectDirectory = options.chdir; - - const editorVersion = await determineEditorVersion(projectDirectory); + withErrorLogger(log, async function (packageSpecs, options) { + const projectDirectory = options.chdir; - if (typeof editorVersion === "string") - log.warn( - "editor.version", - `${editorVersion} is unknown, the editor version check is disabled` - ); - - const homePath = getHomePathFromEnv(process.env); - const upmConfigPath = getUserUpmConfigPathFor( - process.env, - homePath, - options.systemUser - ); + const editorVersion = await determineEditorVersion(projectDirectory); - const sources = await Promise.all( - (options.registry ?? [openupmRegistryUrl]).map((it) => - getRegistryAuth(upmConfigPath, it) - ) + if (typeof editorVersion === "string") + log.warn( + "editor.version", + `${editorVersion} is unknown, the editor version check is disabled` ); - if (options.upstream) sources.push(unityRegistry); - - const addResults = await addDependencies( - projectDirectory, - typeof editorVersion === "string" ? null : editorVersion, - sources, - options.force, - options.test, - packageSpecs - ); - - recordEntries(addResults) - .map(([packageName, addResult]) => { - switch (addResult.type) { - case "added": - return `added ${makePackageSpec( - packageName, - addResult.version - )}`; - case "upgraded": - return `modified ${packageName} ${addResult.fromVersion} => ${addResult.toVersion}`; - case "noChange": - return `existed ${makePackageSpec( - packageName, - addResult.version - )}`; - } - }) - .forEach((message) => { - log.notice("", message); - }); - - log.notice("", "please open Unity project to apply changes."); - } - ) + const homePath = getHomePathFromEnv(process.env); + const upmConfigPath = getUserUpmConfigPathFor( + process.env, + homePath, + options.systemUser + ); + + const sources = await Promise.all( + (options.registry ?? [openupmRegistryUrl]).map((it) => + getRegistryAuth(upmConfigPath, it) + ) + ); + + if (options.upstream) sources.push(unityRegistry); + + const addResults = await addDependencies( + projectDirectory, + typeof editorVersion === "string" ? null : editorVersion, + sources, + options.force, + options.test, + packageSpecs + ); + + recordEntries(addResults) + .map(([packageName, addResult]) => { + switch (addResult.type) { + case "added": + return `added ${makePackageSpec( + packageName, + addResult.version + )}`; + case "upgraded": + return `modified ${packageName} ${addResult.fromVersion} => ${addResult.toVersion}`; + case "noChange": + return `existed ${makePackageSpec( + packageName, + addResult.version + )}`; + } + }) + .forEach((message) => { + log.notice("", message); + }); + + log.notice("", "please open Unity project to apply changes."); + }) ); }