fix(cli): add --base-url option to add possibility of setting every arg without needing to add a workspace first

This commit is contained in:
Ruben Fiszel
2024-09-07 12:44:27 +02:00
parent dcf817de02
commit d1e46d7dfa
3 changed files with 24 additions and 0 deletions
+17
View File
@@ -52,6 +52,23 @@ async function tryResolveWorkspace(
export async function resolveWorkspace(
opts: GlobalOptions
): Promise<Workspace> {
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));
+6
View File
@@ -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 <token:string>",
"Specify an API token. This will override any stored token."
)
.globalOption(
"--base-url <baseUrl:string>",
"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 <headers:string>",
"Specify headers to use for all requests. e.g: \"HEADERS='h1: v1, h2: v2'\""
+1
View File
@@ -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;
};