mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-09-05 16:03:47 +00:00
Allow workspace to be newly created (#1052)
This commit is contained in:
+1
-2
@@ -66,9 +66,8 @@ try {
|
||||
} catch (e) {
|
||||
if (e.name === "ApiError") {
|
||||
console.log("Server failed. " + e.statusText + ": " + e.body);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
||||
export default command;
|
||||
|
||||
+46
-2
@@ -2,7 +2,16 @@
|
||||
import { GlobalOptions } from "./types.ts";
|
||||
import { getRootStore } from "./store.ts";
|
||||
import { loginInteractive, tryGetLoginInfo } from "./login.ts";
|
||||
import { colors, Command, DelimiterStream, Input, Table } from "./deps.ts";
|
||||
import {
|
||||
colors,
|
||||
Command,
|
||||
DelimiterStream,
|
||||
Input,
|
||||
setClient,
|
||||
Table,
|
||||
WorkspaceService,
|
||||
} from "./deps.ts";
|
||||
import { requireLogin } from "./context.ts";
|
||||
|
||||
export type Workspace = {
|
||||
remote: string;
|
||||
@@ -132,7 +141,11 @@ async function switchC(opts: GlobalOptions, workspaceName: string) {
|
||||
}
|
||||
|
||||
export async function add(
|
||||
opts: GlobalOptions,
|
||||
opts: GlobalOptions & {
|
||||
create: boolean;
|
||||
createWorkspaceName: string | undefined;
|
||||
createUsername: string;
|
||||
},
|
||||
workspaceName: string | undefined,
|
||||
workspaceId: string | undefined,
|
||||
remote: string | undefined,
|
||||
@@ -178,6 +191,25 @@ export async function add(
|
||||
token = await loginInteractive(remote);
|
||||
}
|
||||
|
||||
if (opts.create) {
|
||||
setClient(token, remote.substring(0, remote.length - 1));
|
||||
|
||||
if (
|
||||
!await WorkspaceService.existsWorkspace({
|
||||
requestBody: { id: workspaceId },
|
||||
})
|
||||
) {
|
||||
console.log(colors.yellow("Workspace does not exist. Creating..."));
|
||||
await WorkspaceService.createWorkspace({
|
||||
requestBody: {
|
||||
id: workspaceId,
|
||||
name: opts.createWorkspaceName ?? workspaceId,
|
||||
username: opts.createUsername,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
await addWorkspace({
|
||||
name: workspaceName,
|
||||
remote: remote,
|
||||
@@ -224,6 +256,18 @@ const command = new Command()
|
||||
.command("add")
|
||||
.description("Add a workspace")
|
||||
.arguments("[workspace_name:string] [workspace_id:string] [remote:string]")
|
||||
.option("-c --create", "Create the workspace if it does not exist")
|
||||
.option(
|
||||
"--create-workspace-name <workspace_name:string>",
|
||||
"Specify the workspace name. Ignored if --create is not specified or the workspace already exists. Will default to the workspace id.",
|
||||
)
|
||||
.option(
|
||||
"--create-username <username:string>",
|
||||
"Specify your own username in the newly created workspace. Ignored if --create is not specified or the workspace already exists.",
|
||||
{
|
||||
default: "admin",
|
||||
},
|
||||
)
|
||||
.action(add as any)
|
||||
.command("remove")
|
||||
.description("Remove a workspace")
|
||||
|
||||
Reference in New Issue
Block a user