-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathcommand.ts
More file actions
70 lines (64 loc) · 2.06 KB
/
Copy pathcommand.ts
File metadata and controls
70 lines (64 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { resolve } from "node:path";
import { boolean, CLIError, positional, string } from "@superset/cli-framework";
import { getHostId } from "@superset/shared/host-info";
import { command } from "../../../lib/command";
import { resolveHostTarget } from "../../../lib/host-target";
export default command({
description: "Update a workspace on a host (default: this machine)",
args: [positional("id").required().desc("Workspace UUID")],
options: {
host: string().desc("Host the workspace lives on (default: this machine)"),
name: string().desc("Workspace name"),
taskId: string().desc("Link the workspace to a task by id"),
clearTask: boolean().desc("Unlink the workspace from its current task"),
worktreePath: string().desc(
"Re-point the workspace at a worktree that was moved on disk",
),
},
run: async ({ ctx, args, options }) => {
const id = args.id as string;
const organizationId = ctx.config.organizationId;
if (!organizationId) {
throw new CLIError("No active organization", "Run: superset auth login");
}
if (options.taskId !== undefined && options.clearTask) {
throw new CLIError(
"Cannot combine --task-id and --clear-task",
"Pass one or the other",
);
}
const taskId = options.clearTask
? null
: options.taskId !== undefined
? options.taskId
: undefined;
if (
options.name === undefined &&
taskId === undefined &&
options.worktreePath === undefined
) {
throw new CLIError(
"No fields to update",
"Pass --name, --task-id, --clear-task, or --worktree-path",
);
}
const target = await resolveHostTarget({
requestedHostId: options.host ?? getHostId(),
organizationId,
userJwt: ctx.bearer,
api: ctx.api,
});
const updated = await target.client.workspace.update.mutate({
id,
...(options.name !== undefined ? { name: options.name } : {}),
...(taskId !== undefined ? { taskId } : {}),
...(options.worktreePath !== undefined
? { worktreePath: resolve(options.worktreePath) }
: {}),
});
return {
data: updated,
message: `Updated workspace ${id}`,
};
},
});