Skip to content

Commit

Permalink
fix(cli): add --base-url option to add possibility of setting every a…
Browse files Browse the repository at this point in the history
…rg without needing to add a workspace first
  • Loading branch information
rubenfiszel committed Sep 7, 2024
1 parent f006458 commit 1e813b2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cli/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
6 changes: 6 additions & 0 deletions cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -49,6 +50,7 @@ export {
hubPull,
pull,
push,
workspaceAdd,
};

// addEventListener("error", (event) => {
Expand Down Expand Up @@ -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'\""
Expand Down
1 change: 1 addition & 0 deletions cli/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit 1e813b2

Please sign in to comment.