@cargo-ai/cli 1.0.20 → 1.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspace.d.ts","sourceRoot":"","sources":["../../../src/commands/auth/workspace.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"workspace.d.ts","sourceRoot":"","sources":["../../../src/commands/auth/workspace.ts"],"names":[],"mappings":"AAeA,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAyBF,wBAAsB,gBAAgB,CAAC,IAAI,EAAE;IAC3C,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;CAClC,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAoH7B"}
|
|
@@ -1,6 +1,25 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
1
2
|
import * as readline from "node:readline/promises";
|
|
3
|
+
import * as tty from "node:tty";
|
|
2
4
|
import { createApi } from "../../api.js";
|
|
3
5
|
import { ExitCodes, failWith, info, startSpinner, success, } from "../runHandler.js";
|
|
6
|
+
// Interactive prompts must not assume stdin is a terminal: `curl | sh`
|
|
7
|
+
// installers and agent-driven shells pipe stdin while the controlling
|
|
8
|
+
// terminal stays reachable via /dev/tty. Prefer stdin when it is a TTY,
|
|
9
|
+
// otherwise fall back to opening /dev/tty directly.
|
|
10
|
+
function openPromptInput() {
|
|
11
|
+
if (process.stdin.isTTY === true) {
|
|
12
|
+
return { stream: process.stdin, close: () => undefined };
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
const fd = fs.openSync("/dev/tty", "r");
|
|
16
|
+
const stream = new tty.ReadStream(fd);
|
|
17
|
+
return { stream, close: () => stream.destroy() };
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
4
23
|
export async function resolveWorkspace(opts) {
|
|
5
24
|
const api = createApi({
|
|
6
25
|
baseUrl: opts.baseUrl,
|
|
@@ -28,10 +47,17 @@ export async function resolveWorkspace(opts) {
|
|
|
28
47
|
return { uuid: matchedWorkspace.uuid, name: matchedWorkspace.name };
|
|
29
48
|
}
|
|
30
49
|
if (workspaces.length === 0) {
|
|
31
|
-
|
|
50
|
+
const promptInput = openPromptInput();
|
|
51
|
+
if (promptInput === undefined) {
|
|
32
52
|
failWith("No workspaces found.", { code: ExitCodes.NotFound });
|
|
33
53
|
}
|
|
34
|
-
|
|
54
|
+
let name;
|
|
55
|
+
try {
|
|
56
|
+
name = await promptWorkspaceName(promptInput.stream);
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
promptInput.close();
|
|
60
|
+
}
|
|
35
61
|
if (name === undefined) {
|
|
36
62
|
failWith("No workspace name provided.", {
|
|
37
63
|
code: ExitCodes.InvalidUsage,
|
|
@@ -63,18 +89,25 @@ export async function resolveWorkspace(opts) {
|
|
|
63
89
|
}
|
|
64
90
|
return { uuid: firstWorkspace.uuid, name: firstWorkspace.name };
|
|
65
91
|
}
|
|
66
|
-
|
|
67
|
-
|
|
92
|
+
const promptInput = openPromptInput();
|
|
93
|
+
if (promptInput === undefined) {
|
|
94
|
+
failWith("Multiple workspaces available and no interactive terminal; pass --workspace-uuid <uuid> (or set CARGO_WORKSPACE_UUID when using install.sh) to select one.", { code: ExitCodes.InvalidUsage });
|
|
95
|
+
}
|
|
96
|
+
let selectedWorkspace;
|
|
97
|
+
try {
|
|
98
|
+
selectedWorkspace = await promptWorkspaceSelection(workspaces, promptInput.stream);
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
promptInput.close();
|
|
68
102
|
}
|
|
69
|
-
const selectedWorkspace = await promptWorkspaceSelection(workspaces);
|
|
70
103
|
if (selectedWorkspace === undefined) {
|
|
71
104
|
failWith("No workspace selected.", { code: ExitCodes.InvalidUsage });
|
|
72
105
|
}
|
|
73
106
|
return selectedWorkspace;
|
|
74
107
|
}
|
|
75
|
-
async function promptWorkspaceName() {
|
|
108
|
+
async function promptWorkspaceName(input) {
|
|
76
109
|
const rl = readline.createInterface({
|
|
77
|
-
input
|
|
110
|
+
input,
|
|
78
111
|
output: process.stderr,
|
|
79
112
|
});
|
|
80
113
|
try {
|
|
@@ -90,9 +123,9 @@ async function promptWorkspaceName() {
|
|
|
90
123
|
rl.close();
|
|
91
124
|
}
|
|
92
125
|
}
|
|
93
|
-
async function promptWorkspaceSelection(workspaces) {
|
|
126
|
+
async function promptWorkspaceSelection(workspaces, input) {
|
|
94
127
|
const rl = readline.createInterface({
|
|
95
|
-
input
|
|
128
|
+
input,
|
|
96
129
|
output: process.stderr,
|
|
97
130
|
});
|
|
98
131
|
try {
|