-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathassign.ts
More file actions
125 lines (108 loc) · 3.36 KB
/
assign.ts
File metadata and controls
125 lines (108 loc) · 3.36 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import {
assignFiles,
assignFilesToNewWorkspace,
listUnassigned,
} from "@array/core/commands/assign";
import { cyan, dim, formatSuccess, green, message } from "../utils/output";
import { requireArg, unwrap } from "../utils/run";
export async function assign(args: string[]): Promise<void> {
if (args.length === 0) {
message("Usage: arr assign <file...> <workspace>");
message(" arr assign <file...> --new <workspace-name>");
message("");
message("Examples:");
message(" arr assign config.json agent-a");
message(" arr assign file1.txt file2.txt agent-b");
message(' arr assign "src/**/*.ts" --new refactor');
return;
}
// Check for --new flag
const newIndex = args.indexOf("--new");
const nIndex = args.indexOf("-n");
const newFlagIndex = newIndex !== -1 ? newIndex : nIndex;
if (newFlagIndex !== -1) {
// Everything before --new is files, next arg is workspace name
const files = args.slice(0, newFlagIndex);
const newWorkspaceName = args[newFlagIndex + 1];
requireArg(files[0], "Usage: arr assign <file...> --new <workspace-name>");
requireArg(
newWorkspaceName,
"Usage: arr assign <file...> --new <workspace-name>",
);
const result = unwrap(
await assignFilesToNewWorkspace(files, newWorkspaceName),
);
if (result.files.length === 1) {
message(
formatSuccess(
`Assigned ${cyan(result.files[0])} to new workspace ${green(result.to)}`,
),
);
} else {
message(
formatSuccess(
`Assigned ${result.files.length} files to new workspace ${green(result.to)}`,
),
);
for (const file of result.files) {
message(` ${cyan(file)}`);
}
}
return;
}
// Regular assign to existing workspace
// Last arg is workspace, everything else is files
if (args.length < 2) {
message("Usage: arr assign <file...> <workspace>");
return;
}
const files = args.slice(0, -1);
const targetWorkspace = args[args.length - 1];
requireArg(files[0], "Usage: arr assign <file...> <workspace>");
requireArg(targetWorkspace, "Usage: arr assign <file...> <workspace>");
const result = unwrap(await assignFiles(files, targetWorkspace));
if (result.files.length === 1) {
message(
formatSuccess(`Assigned ${cyan(result.files[0])} to ${green(result.to)}`),
);
} else {
message(
formatSuccess(
`Assigned ${result.files.length} files to ${green(result.to)}`,
),
);
for (const file of result.files) {
message(` ${cyan(file)}`);
}
}
}
export async function unassigned(
subcommand: string,
_args: string[],
): Promise<void> {
switch (subcommand) {
case "list":
case "ls": {
const result = unwrap(await listUnassigned());
if (result.files.length === 0) {
message(dim("No unassigned files"));
return;
}
message(
`${result.files.length} unassigned file${result.files.length === 1 ? "" : "s"}:`,
);
message("");
for (const file of result.files) {
message(` ${cyan(file)}`);
}
message("");
message(`Assign files: ${dim("arr assign <file...> <workspace>")}`);
break;
}
default:
message("Usage: arr unassigned <list>");
message("");
message("Subcommands:");
message(" list List files in unassigned workspace");
}
}