-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.ts
More file actions
98 lines (84 loc) · 2.87 KB
/
Copy pathindex.ts
File metadata and controls
98 lines (84 loc) · 2.87 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { Command, Option } from "commander";
import { runBranchList, runBranchRemove } from "../../controllers/branch";
import {
renderBranchList,
renderBranchRemove,
serializeBranchList,
serializeBranchRemove,
} from "../../presenters/branch";
import { attachCommandDescriptor } from "../../shell/command-meta";
import { runCommand } from "../../shell/command-runner";
import {
addCompactGlobalFlags,
addGlobalFlags,
} from "../../shell/global-flags";
import { type CliRuntime, configureRuntimeCommand } from "../../shell/runtime";
import type { BranchListResult, BranchRemoveResult } from "../../types/branch";
export function createBranchCommand(runtime: CliRuntime): Command {
const branch = attachCommandDescriptor(
configureRuntimeCommand(new Command("branch"), runtime),
"branch",
);
addCompactGlobalFlags(branch);
branch.addCommand(createBranchListCommand(runtime));
branch.addCommand(createBranchRemoveCommand(runtime));
return branch;
}
function createBranchRemoveCommand(runtime: CliRuntime): Command {
const command = attachCommandDescriptor(
configureRuntimeCommand(new Command("remove"), runtime),
"branch.remove",
);
command
.argument("<branch>", "Branch id or git name")
.addOption(new Option("--project <id-or-name>", "Project id or name"))
.addOption(
new Option("--confirm <branch-id>", "Exact branch id required to remove"),
)
.addOption(
new Option(
"--cascade",
"Also remove the branch's apps and databases (preview branches only)",
),
);
addGlobalFlags(command);
command.action(async (branchRef: string, options) => {
const projectRef = (options as { project?: string }).project;
const confirm = (options as { confirm?: string }).confirm;
const cascade = (options as { cascade?: boolean }).cascade;
await runCommand<BranchRemoveResult>(
runtime,
"branch.remove",
options as Record<string, unknown>,
(context) =>
runBranchRemove(context, branchRef, { projectRef, confirm, cascade }),
{
renderHuman: (context, descriptor, result) =>
renderBranchRemove(context, descriptor, result),
renderJson: (result) => serializeBranchRemove(result),
},
);
});
return command;
}
function createBranchListCommand(runtime: CliRuntime): Command {
const command = attachCommandDescriptor(
configureRuntimeCommand(new Command("list"), runtime),
"branch.list",
);
addGlobalFlags(command);
command.action(async (options) => {
await runCommand<BranchListResult>(
runtime,
"branch.list",
options as Record<string, unknown>,
(context) => runBranchList(context),
{
renderHuman: (context, descriptor, result) =>
renderBranchList(context, descriptor, result),
renderJson: (result) => serializeBranchList(result),
},
);
});
return command;
}