diff --git a/cli/context.ts b/cli/context.ts index e73415f5dc..808161927c 100644 --- a/cli/context.ts +++ b/cli/context.ts @@ -52,6 +52,23 @@ async function tryResolveWorkspace( export async function resolveWorkspace( opts: GlobalOptions ): Promise { + if (opts.baseUrl) { + if (opts.workspace && opts.token) { + return { + remote: new URL(opts.baseUrl).toString(), // add trailing slash if not present + workspaceId: opts.workspace, + name: opts.workspace, + token: opts.token, + }; + } else { + log.info( + colors.red( + "If you specify a base URL with --base-url, you must also specify a workspace (--workspace) and token (--token)." + ) + ); + return Deno.exit(-1); + } + } const res = await tryResolveWorkspace(opts); if (res.isError) { log.info(colors.red.bold(res.error)); diff --git a/cli/main.ts b/cli/main.ts index b0a3d662d2..5ead08b036 100644 --- a/cli/main.ts +++ b/cli/main.ts @@ -29,6 +29,7 @@ import { getHeaders } from "./utils.ts"; import { NpmProvider } from "./upgrade.ts"; import { pull as hubPull } from "./hub.ts"; import { pull, push } from "./sync.ts"; +import { add as workspaceAdd } from "./workspace.ts"; export { flow, @@ -49,6 +50,7 @@ export { hubPull, pull, push, + workspaceAdd, }; // addEventListener("error", (event) => { @@ -80,6 +82,10 @@ let command: any = new Command() "--token ", "Specify an API token. This will override any stored token." ) + .globalOption( + "--base-url ", + "Specify the base URL of the API. If used, --token and --workspace are required and no local remote/workspace already set will be used." + ) .env( "HEADERS ", "Specify headers to use for all requests. e.g: \"HEADERS='h1: v1, h2: v2'\"" diff --git a/cli/types.ts b/cli/types.ts index 49f7a42b9a..a4632215ab 100644 --- a/cli/types.ts +++ b/cli/types.ts @@ -45,6 +45,7 @@ export interface DifferenceChange { export type Difference = DifferenceCreate | DifferenceRemove | DifferenceChange; export type GlobalOptions = { + baseUrl: string | undefined; workspace: string | undefined; token: string | undefined; };