disk 1.10.0 → 1.12.0
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.
- package/README.md +8 -0
- package/dist/archil-CLQrudfP.d.cts +1581 -0
- package/dist/archil-CLQrudfP.d.mts +1581 -0
- package/dist/cli.mjs +2 -3
- package/dist/index.cjs +257 -73
- package/dist/index.d.cts +2 -695
- package/dist/index.d.mts +2 -695
- package/dist/index.mjs +1 -1
- package/dist/internal/tools.d.cts +1 -1
- package/dist/internal/tools.d.mts +1 -1
- package/dist/sandbox-cli.mjs +5 -10
- package/dist/{sandbox-options-DV7SSadf.mjs → sandbox-options-Cz_oVr-y.mjs} +375 -21
- package/dist/{src-BND_QqPx.mjs → src-V9HdQW-c.mjs} +257 -51
- package/package.json +12 -9
- package/dist/disk-DZkPOSQD.d.cts +0 -784
- package/dist/disk-DZkPOSQD.d.mts +0 -784
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as ArchilError, C as Disk, D as VERSION, E as USER_AGENT, M as ImageBuildError, N as SandboxFileTransferError, P as SandboxPauseError, S as Disks, T as effectiveUploadPartSize, _ as Sandbox, a as deleteApiKey, b as SandboxProcesses, c as getSandbox, d as listSandboxes, f as workspace, g as Sandboxes, h as Tokens, i as createSandbox, j as ArchilS3Error, k as ArchilApiError, l as listApiKeys, m as Workspace, n as createApiKey, o as exec, p as Archil, r as createDisk, s as getDisk, t as configure, u as listDisks, v as SandboxFiles, w as DiskMultipart, x as Images, y as SandboxProcess } from "./src-
|
|
1
|
+
import { A as ArchilError, C as Disk, D as VERSION, E as USER_AGENT, M as ImageBuildError, N as SandboxFileTransferError, P as SandboxPauseError, S as Disks, T as effectiveUploadPartSize, _ as Sandbox, a as deleteApiKey, b as SandboxProcesses, c as getSandbox, d as listSandboxes, f as workspace, g as Sandboxes, h as Tokens, i as createSandbox, j as ArchilS3Error, k as ArchilApiError, l as listApiKeys, m as Workspace, n as createApiKey, o as exec, p as Archil, r as createDisk, s as getDisk, t as configure, u as listDisks, v as SandboxFiles, w as DiskMultipart, x as Images, y as SandboxProcess } from "./src-V9HdQW-c.mjs";
|
|
2
2
|
export { Archil, ArchilApiError, ArchilError, ArchilS3Error, Disk, DiskMultipart, Disks, ImageBuildError, Images, Sandbox, SandboxFileTransferError, SandboxFiles, SandboxPauseError, SandboxProcess, SandboxProcesses, Sandboxes, Tokens, USER_AGENT, VERSION, Workspace, configure, createApiKey, createDisk, createSandbox, deleteApiKey, effectiveUploadPartSize, exec, getDisk, getSandbox, listApiKeys, listDisks, listSandboxes, workspace };
|
package/dist/sandbox-cli.mjs
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { k as ArchilApiError, p as Archil } from "./src-
|
|
3
|
-
import { a as addGlobalOptions, c as resolveProgramCredentials, i as validateSandboxName, l as renderTable, n as parseCreateSandboxOptions, o as addProfileCommands, r as parseRunOptions, s as isProfileCommand } from "./sandbox-options-
|
|
2
|
+
import { k as ArchilApiError, p as Archil } from "./src-V9HdQW-c.mjs";
|
|
3
|
+
import { a as addGlobalOptions, c as resolveProgramCredentials, d as Command, i as validateSandboxName, l as renderTable, n as parseCreateSandboxOptions, o as addProfileCommands, r as parseRunOptions, s as isProfileCommand, u as spinner } from "./sandbox-options-Cz_oVr-y.mjs";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
|
-
import { Command } from "commander";
|
|
6
|
-
import { spinner } from "@clack/prompts";
|
|
7
5
|
import { createInterface } from "node:readline/promises";
|
|
8
|
-
import { validate } from "uuid";
|
|
9
6
|
//#region src/cli/sandbox-output.ts
|
|
10
7
|
function parseOutputFormat(value) {
|
|
11
8
|
if (value !== "table" && value !== "json") throw new Error("Output format must be 'table' or 'json'");
|
|
@@ -216,8 +213,9 @@ const SANDBOX_ACTIONS = {
|
|
|
216
213
|
deleting: [],
|
|
217
214
|
deleted: []
|
|
218
215
|
};
|
|
216
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
219
217
|
async function resolveSandbox(service, idOrName) {
|
|
220
|
-
if (
|
|
218
|
+
if (UUID.test(idOrName)) return service.get(idOrName);
|
|
221
219
|
const byName = (await service.list()).filter(({ name }) => name === idOrName);
|
|
222
220
|
if (byName.length === 0) throw new Error(`No sandbox found with id or name '${idOrName}'`);
|
|
223
221
|
if (byName.length > 1) throw new Error(`Multiple sandboxes are named '${idOrName}'; pass an exact sandbox id`);
|
|
@@ -250,10 +248,7 @@ function createSandboxProgram(dependencies) {
|
|
|
250
248
|
const output = (value) => stdout.write(`${value}\n`);
|
|
251
249
|
const withSpinner = async (label, enabled, operation) => {
|
|
252
250
|
if (!enabled || !stderr.isTTY) return operation();
|
|
253
|
-
const progress = spinner(
|
|
254
|
-
output: stderr,
|
|
255
|
-
withGuide: false
|
|
256
|
-
});
|
|
251
|
+
const progress = spinner(stderr);
|
|
257
252
|
progress.start(label);
|
|
258
253
|
try {
|
|
259
254
|
return await operation();
|
|
@@ -1,9 +1,334 @@
|
|
|
1
|
-
import { O as REGION_URLS, p as Archil } from "./src-
|
|
2
|
-
import { Option } from "commander";
|
|
3
|
-
import { isCancel, password, spinner } from "@clack/prompts";
|
|
1
|
+
import { O as REGION_URLS, p as Archil } from "./src-V9HdQW-c.mjs";
|
|
4
2
|
import { chmod, mkdir, open, readFile, rename, rm, stat } from "node:fs/promises";
|
|
5
3
|
import { dirname, join } from "node:path";
|
|
6
4
|
import { homedir } from "node:os";
|
|
5
|
+
//#region src/cli/command.ts
|
|
6
|
+
/** A usage problem with the command line itself (unknown option, missing argument). */
|
|
7
|
+
var CliUsageError = class extends Error {};
|
|
8
|
+
function camelCase(name) {
|
|
9
|
+
return name.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
10
|
+
}
|
|
11
|
+
var Option = class {
|
|
12
|
+
flags;
|
|
13
|
+
description;
|
|
14
|
+
short;
|
|
15
|
+
long;
|
|
16
|
+
attribute;
|
|
17
|
+
valueName;
|
|
18
|
+
negate;
|
|
19
|
+
envVar;
|
|
20
|
+
parser;
|
|
21
|
+
defaultValue;
|
|
22
|
+
constructor(flags, description = "") {
|
|
23
|
+
this.flags = flags;
|
|
24
|
+
this.description = description;
|
|
25
|
+
const match = /^(?:-([A-Za-z]),\s*)?--([A-Za-z][\w-]*)(?:\s+<([^>]+)>)?$/.exec(flags);
|
|
26
|
+
if (!match) throw new Error(`Unsupported option flags '${flags}'`);
|
|
27
|
+
this.short = match[1];
|
|
28
|
+
this.long = match[2];
|
|
29
|
+
this.valueName = match[3];
|
|
30
|
+
this.negate = this.long.startsWith("no-");
|
|
31
|
+
this.attribute = camelCase(this.negate ? this.long.slice(3) : this.long);
|
|
32
|
+
if (this.negate) this.defaultValue = true;
|
|
33
|
+
}
|
|
34
|
+
/** Fall back to this environment variable when the option isn't given. */
|
|
35
|
+
env(name) {
|
|
36
|
+
this.envVar = name;
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
get takesValue() {
|
|
40
|
+
return this.valueName !== void 0;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
function parseArgument(spec) {
|
|
44
|
+
const match = /^([<[])([^>\]]+?)(\.\.\.)?[>\]]$/.exec(spec);
|
|
45
|
+
if (!match) throw new Error(`Unsupported argument '${spec}'`);
|
|
46
|
+
return {
|
|
47
|
+
name: match[2],
|
|
48
|
+
required: match[1] === "<",
|
|
49
|
+
variadic: match[3] !== void 0
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function argumentUsage(argument) {
|
|
53
|
+
const name = `${argument.name}${argument.variadic ? "..." : ""}`;
|
|
54
|
+
return argument.required ? `<${name}>` : `[${name}]`;
|
|
55
|
+
}
|
|
56
|
+
const HELP_OPTION = new Option("-h, --help", "display help for command");
|
|
57
|
+
const VERSION_FLAGS = "-V, --version";
|
|
58
|
+
/** Lay out `[term, description]` rows as an indented two-column list. */
|
|
59
|
+
function formatList(rows) {
|
|
60
|
+
const width = Math.max(...rows.map(([term]) => term.length));
|
|
61
|
+
return rows.map(([term, description]) => ` ${term.padEnd(width)} ${description}`.trimEnd()).join("\n");
|
|
62
|
+
}
|
|
63
|
+
var Command = class Command {
|
|
64
|
+
commands = [];
|
|
65
|
+
parent;
|
|
66
|
+
_name;
|
|
67
|
+
_description = "";
|
|
68
|
+
_version;
|
|
69
|
+
_arguments = [];
|
|
70
|
+
_options = [];
|
|
71
|
+
_action;
|
|
72
|
+
_preActionHooks = [];
|
|
73
|
+
_helpAfter = "";
|
|
74
|
+
_showGlobalOptions = false;
|
|
75
|
+
_values = {};
|
|
76
|
+
_fromCli = /* @__PURE__ */ new Set();
|
|
77
|
+
constructor(name = "") {
|
|
78
|
+
this._name = name;
|
|
79
|
+
}
|
|
80
|
+
name(name) {
|
|
81
|
+
if (name === void 0) return this._name;
|
|
82
|
+
this._name = name;
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
description(text) {
|
|
86
|
+
this._description = text;
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
version(version) {
|
|
90
|
+
this._version = Object.assign(new Option(VERSION_FLAGS, "output the version number"), { version });
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
hook(event, hook) {
|
|
94
|
+
this._preActionHooks.push(hook);
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
/** Add a subcommand, e.g. `get <id|name>` or `run <id> <command...>`, and return it. */
|
|
98
|
+
command(spec) {
|
|
99
|
+
const [name, ...args] = spec.trim().split(/\s+/);
|
|
100
|
+
const command = new Command(name);
|
|
101
|
+
for (const arg of args) command._arguments.push(parseArgument(arg));
|
|
102
|
+
command.parent = this;
|
|
103
|
+
this.commands.push(command);
|
|
104
|
+
return command;
|
|
105
|
+
}
|
|
106
|
+
option(flags, description, parserOrDefault, defaultValue) {
|
|
107
|
+
const option = new Option(flags, description);
|
|
108
|
+
if (typeof parserOrDefault === "function") {
|
|
109
|
+
option.parser = parserOrDefault;
|
|
110
|
+
if (defaultValue !== void 0) option.defaultValue = defaultValue;
|
|
111
|
+
} else if (parserOrDefault !== void 0) option.defaultValue = parserOrDefault;
|
|
112
|
+
return this.addOption(option);
|
|
113
|
+
}
|
|
114
|
+
addOption(option) {
|
|
115
|
+
this._options.push(option);
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
configureHelp(settings) {
|
|
119
|
+
this._showGlobalOptions = settings.showGlobalOptions ?? this._showGlobalOptions;
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
addHelpText(position, text) {
|
|
123
|
+
this._helpAfter += text;
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
action(handler) {
|
|
127
|
+
this._action = handler;
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
opts() {
|
|
131
|
+
return { ...this._values };
|
|
132
|
+
}
|
|
133
|
+
/** Parse `argv` (`[node, script, ...args]`) and run the selected command's action. */
|
|
134
|
+
async parseAsync(argv) {
|
|
135
|
+
await this._run(argv.slice(2));
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
138
|
+
_ancestors() {
|
|
139
|
+
const chain = [];
|
|
140
|
+
for (let command = this; command; command = command.parent) chain.unshift(command);
|
|
141
|
+
return chain;
|
|
142
|
+
}
|
|
143
|
+
_commandPath() {
|
|
144
|
+
return this._ancestors().map((command) => command._name).join(" ");
|
|
145
|
+
}
|
|
146
|
+
_root() {
|
|
147
|
+
return this._ancestors()[0];
|
|
148
|
+
}
|
|
149
|
+
_reset() {
|
|
150
|
+
this._values = {};
|
|
151
|
+
this._fromCli.clear();
|
|
152
|
+
for (const option of this._options) if (option.defaultValue !== void 0) this._values[option.attribute] = option.defaultValue;
|
|
153
|
+
}
|
|
154
|
+
/** Find an option on this command or an ancestor, by `--long` name or `-s` flag. */
|
|
155
|
+
_findOption(matches) {
|
|
156
|
+
for (const owner of this._ancestors().reverse()) {
|
|
157
|
+
const option = owner._options.find(matches);
|
|
158
|
+
if (option) return {
|
|
159
|
+
owner,
|
|
160
|
+
option
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
_setOption(owner, option, value) {
|
|
165
|
+
if (!option.takesValue) owner._values[option.attribute] = !option.negate;
|
|
166
|
+
else {
|
|
167
|
+
const previous = owner._values[option.attribute];
|
|
168
|
+
owner._values[option.attribute] = option.parser ? option.parser(value, previous) : value;
|
|
169
|
+
}
|
|
170
|
+
owner._fromCli.add(option.attribute);
|
|
171
|
+
}
|
|
172
|
+
_applyEnvironment() {
|
|
173
|
+
for (const option of this._options) {
|
|
174
|
+
if (!option.envVar || this._fromCli.has(option.attribute)) continue;
|
|
175
|
+
const value = process.env[option.envVar];
|
|
176
|
+
if (value === void 0) continue;
|
|
177
|
+
this._values[option.attribute] = option.parser ? option.parser(value, this._values[option.attribute]) : value;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
async _run(args) {
|
|
181
|
+
this._reset();
|
|
182
|
+
const operands = [];
|
|
183
|
+
let index = 0;
|
|
184
|
+
const takeValue = (option, inline) => {
|
|
185
|
+
if (inline !== void 0) return inline;
|
|
186
|
+
const value = args[index++];
|
|
187
|
+
if (value === void 0) throw new CliUsageError(`error: option '${option.flags}' argument missing`);
|
|
188
|
+
return value;
|
|
189
|
+
};
|
|
190
|
+
while (index < args.length) {
|
|
191
|
+
const token = args[index++];
|
|
192
|
+
if (token === "--") {
|
|
193
|
+
operands.push(...args.slice(index));
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
if (token.startsWith("--")) {
|
|
197
|
+
const eq = token.indexOf("=");
|
|
198
|
+
const long = token.slice(2, eq === -1 ? void 0 : eq);
|
|
199
|
+
const inline = eq === -1 ? void 0 : token.slice(eq + 1);
|
|
200
|
+
if (long === "help") return this._printHelp();
|
|
201
|
+
if (long === "version" && this._root()._version) return this._printVersion();
|
|
202
|
+
const found = this._findOption((option) => option.long === long);
|
|
203
|
+
if (!found) throw new CliUsageError(`error: unknown option '--${long}'`);
|
|
204
|
+
if (!found.option.takesValue && inline !== void 0) throw new CliUsageError(`error: option '${found.option.flags}' does not take an argument`);
|
|
205
|
+
this._setOption(found.owner, found.option, found.option.takesValue ? takeValue(found.option, inline) : void 0);
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
if (token.startsWith("-") && token.length > 1) {
|
|
209
|
+
for (let position = 1; position < token.length; position++) {
|
|
210
|
+
const flag = token[position];
|
|
211
|
+
if (flag === "h") return this._printHelp();
|
|
212
|
+
if (flag === "V" && this._root()._version) return this._printVersion();
|
|
213
|
+
const found = this._findOption((option) => option.short === flag);
|
|
214
|
+
if (!found) throw new CliUsageError(`error: unknown option '${position === 1 ? token : `-${flag}`}'`);
|
|
215
|
+
if (found.option.takesValue) {
|
|
216
|
+
const rest = token.slice(position + 1);
|
|
217
|
+
this._setOption(found.owner, found.option, takeValue(found.option, rest === "" ? void 0 : rest));
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
this._setOption(found.owner, found.option, void 0);
|
|
221
|
+
}
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
if (operands.length === 0 && this.commands.length > 0) {
|
|
225
|
+
if (token === "help") return (this.commands.find((command) => command._name === args[index]) ?? this)._printHelp();
|
|
226
|
+
const subcommand = this.commands.find((command) => command._name === token);
|
|
227
|
+
if (!subcommand) throw new CliUsageError(`error: unknown command '${token}'`);
|
|
228
|
+
return subcommand._run(args.slice(index));
|
|
229
|
+
}
|
|
230
|
+
operands.push(token);
|
|
231
|
+
}
|
|
232
|
+
for (const command of this._ancestors()) command._applyEnvironment();
|
|
233
|
+
if (!this._action) {
|
|
234
|
+
if (this.commands.length > 0) throw new CliUsageError(this.helpInformation());
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
const values = [];
|
|
238
|
+
for (const [position, argument] of this._arguments.entries()) if (argument.variadic) {
|
|
239
|
+
const rest = operands.slice(position);
|
|
240
|
+
if (argument.required && rest.length === 0) throw new CliUsageError(`error: missing required argument '${argument.name}'`);
|
|
241
|
+
values.push(rest);
|
|
242
|
+
} else {
|
|
243
|
+
const value = operands[position];
|
|
244
|
+
if (argument.required && value === void 0) throw new CliUsageError(`error: missing required argument '${argument.name}'`);
|
|
245
|
+
values.push(value);
|
|
246
|
+
}
|
|
247
|
+
if (!this._arguments[this._arguments.length - 1]?.variadic && operands.length > this._arguments.length) throw new CliUsageError(`error: too many arguments for '${this._name}'. Expected ${this._arguments.length} argument${this._arguments.length === 1 ? "" : "s"} but got ${operands.length}.`);
|
|
248
|
+
for (const command of this._ancestors()) for (const hook of command._preActionHooks) await hook(command, this);
|
|
249
|
+
await this._action(...values, this.opts(), this);
|
|
250
|
+
}
|
|
251
|
+
_printHelp() {
|
|
252
|
+
process.stdout.write(`${this.helpInformation()}${this._helpAfter}`);
|
|
253
|
+
}
|
|
254
|
+
_printVersion() {
|
|
255
|
+
process.stdout.write(`${this._root()._version.version}\n`);
|
|
256
|
+
}
|
|
257
|
+
_optionRows(options) {
|
|
258
|
+
return options.map((option) => {
|
|
259
|
+
const term = `${option.short ? `-${option.short}, ` : ""}--${option.long}${option.takesValue ? ` <${option.valueName}>` : ""}`;
|
|
260
|
+
const extras = [];
|
|
261
|
+
if (option.takesValue && option.defaultValue !== void 0 && !(Array.isArray(option.defaultValue) && option.defaultValue.length === 0)) extras.push(`default: ${JSON.stringify(option.defaultValue)}`);
|
|
262
|
+
if (option.envVar) extras.push(`env: ${option.envVar}`);
|
|
263
|
+
return [term, extras.length > 0 ? `${option.description} (${extras.join(", ")})` : option.description];
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
/** The command's help text. */
|
|
267
|
+
helpInformation() {
|
|
268
|
+
const usage = [this._commandPath(), "[options]"];
|
|
269
|
+
if (this.commands.length > 0) usage.push("[command]");
|
|
270
|
+
usage.push(...this._arguments.map(argumentUsage));
|
|
271
|
+
const sections = [`Usage: ${usage.join(" ")}`];
|
|
272
|
+
if (this._description) sections.push(this._description);
|
|
273
|
+
const ownOptions = [...this._options];
|
|
274
|
+
if (this === this._root() && this._version) ownOptions.push(this._version);
|
|
275
|
+
sections.push(`Options:\n${formatList(this._optionRows([...ownOptions, HELP_OPTION]))}`);
|
|
276
|
+
if (this._ancestors().some((command) => command._showGlobalOptions)) {
|
|
277
|
+
const inherited = this._ancestors().slice(0, -1).flatMap((command) => command._options);
|
|
278
|
+
if (inherited.length > 0) sections.push(`Global Options:\n${formatList(this._optionRows(inherited))}`);
|
|
279
|
+
}
|
|
280
|
+
if (this.commands.length > 0) {
|
|
281
|
+
const rows = this.commands.map((command) => [[
|
|
282
|
+
command._name,
|
|
283
|
+
...command._options.length > 0 ? ["[options]"] : [],
|
|
284
|
+
...command._arguments.map(argumentUsage)
|
|
285
|
+
].join(" "), command._description]);
|
|
286
|
+
rows.push(["help [command]", "display help for command"]);
|
|
287
|
+
sections.push(`Commands:\n${formatList(rows)}`);
|
|
288
|
+
}
|
|
289
|
+
return `${sections.join("\n\n")}\n`;
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
//#endregion
|
|
293
|
+
//#region src/cli/spinner.ts
|
|
294
|
+
const FRAMES = [
|
|
295
|
+
"◒",
|
|
296
|
+
"◐",
|
|
297
|
+
"◓",
|
|
298
|
+
"◑"
|
|
299
|
+
];
|
|
300
|
+
const CLEAR_LINE = "\r\x1B[2K";
|
|
301
|
+
const HIDE_CURSOR = "\x1B[?25l";
|
|
302
|
+
const SHOW_CURSOR = "\x1B[?25h";
|
|
303
|
+
/** A single-line progress spinner for a TTY stream. */
|
|
304
|
+
function spinner(output) {
|
|
305
|
+
let timer;
|
|
306
|
+
const finish = (line) => {
|
|
307
|
+
if (timer === void 0) return;
|
|
308
|
+
clearInterval(timer);
|
|
309
|
+
timer = void 0;
|
|
310
|
+
output.write(`${CLEAR_LINE}${line}${SHOW_CURSOR}`);
|
|
311
|
+
};
|
|
312
|
+
return {
|
|
313
|
+
start(label) {
|
|
314
|
+
let frame = 0;
|
|
315
|
+
const draw = () => output.write(`${CLEAR_LINE}${FRAMES[frame++ % FRAMES.length]} ${label}`);
|
|
316
|
+
output.write(HIDE_CURSOR);
|
|
317
|
+
draw();
|
|
318
|
+
timer = setInterval(draw, 80);
|
|
319
|
+
},
|
|
320
|
+
stop(message) {
|
|
321
|
+
finish(`◇ ${message}\n`);
|
|
322
|
+
},
|
|
323
|
+
error(message) {
|
|
324
|
+
finish(`■ ${message}\n`);
|
|
325
|
+
},
|
|
326
|
+
clear() {
|
|
327
|
+
finish("");
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
//#endregion
|
|
7
332
|
//#region src/cli/config-paths.ts
|
|
8
333
|
function diskConfigDir(env = process.env, platform = process.platform, home = homedir()) {
|
|
9
334
|
if (env.ARCHIL_DISK_CONFIG_DIR) return env.ARCHIL_DISK_CONFIG_DIR;
|
|
@@ -78,21 +403,53 @@ async function promptSecret(prompt = "API key: ", input = process.stdin, output
|
|
|
78
403
|
for await (const chunk of input) chunks.push(Buffer.from(chunk));
|
|
79
404
|
return validateApiKey(Buffer.concat(chunks).toString("utf8"));
|
|
80
405
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
406
|
+
return readMaskedLine(prompt, input, output);
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Read a line from a TTY in raw mode, echoing `*` per character. An invalid key
|
|
410
|
+
* prints the reason and asks again; Ctrl-C cancels.
|
|
411
|
+
*/
|
|
412
|
+
function readMaskedLine(prompt, input, output) {
|
|
413
|
+
return new Promise((resolve, reject) => {
|
|
414
|
+
const wasRaw = input.isRaw;
|
|
415
|
+
let value = "";
|
|
416
|
+
const finish = (settle) => {
|
|
417
|
+
input.off("data", onData);
|
|
418
|
+
input.setRawMode(wasRaw);
|
|
419
|
+
input.pause();
|
|
420
|
+
output.write("\n");
|
|
421
|
+
settle();
|
|
422
|
+
};
|
|
423
|
+
const onData = (chunk) => {
|
|
424
|
+
for (const char of chunk.toString("utf8")) {
|
|
425
|
+
if (char === "" || char === "" && value === "") {
|
|
426
|
+
finish(() => reject(/* @__PURE__ */ new Error("Profile creation cancelled")));
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
if (char === "\r" || char === "\n") try {
|
|
430
|
+
const key = validateApiKey(value);
|
|
431
|
+
finish(() => resolve(key));
|
|
432
|
+
return;
|
|
433
|
+
} catch (error) {
|
|
434
|
+
output.write(`\n${error instanceof Error ? error.message : String(error)}\n${prompt}`);
|
|
435
|
+
value = "";
|
|
436
|
+
}
|
|
437
|
+
else if (char === "" || char === "\b") {
|
|
438
|
+
if (value) {
|
|
439
|
+
value = value.slice(0, -1);
|
|
440
|
+
output.write("\b \b");
|
|
441
|
+
}
|
|
442
|
+
} else if (char >= " ") {
|
|
443
|
+
value += char;
|
|
444
|
+
output.write("*");
|
|
445
|
+
}
|
|
91
446
|
}
|
|
92
|
-
}
|
|
447
|
+
};
|
|
448
|
+
output.write(prompt);
|
|
449
|
+
input.setRawMode(true);
|
|
450
|
+
input.resume();
|
|
451
|
+
input.on("data", onData);
|
|
93
452
|
});
|
|
94
|
-
if (isCancel(result)) throw new Error("Profile creation cancelled");
|
|
95
|
-
return validateApiKey(result);
|
|
96
453
|
}
|
|
97
454
|
//#endregion
|
|
98
455
|
//#region src/cli/credential-validation.ts
|
|
@@ -221,10 +578,7 @@ function addProfileCommands(program, validateCredential = validateCredentialAndR
|
|
|
221
578
|
const config = await loadProfiles();
|
|
222
579
|
if (global.profile && config.profiles[global.profile]) throw new Error(`Profile '${global.profile}' already exists`);
|
|
223
580
|
const apiKey = validateApiKey(global.apiKey ?? await promptSecret());
|
|
224
|
-
const progress = !global.region && !global.baseUrl && process.stderr.isTTY ? spinner(
|
|
225
|
-
output: process.stderr,
|
|
226
|
-
withGuide: false
|
|
227
|
-
}) : void 0;
|
|
581
|
+
const progress = !global.region && !global.baseUrl && process.stderr.isTTY ? spinner(process.stderr) : void 0;
|
|
228
582
|
progress?.start("Finding the API key's region");
|
|
229
583
|
let region;
|
|
230
584
|
try {
|
|
@@ -347,4 +701,4 @@ function parseRunOptions(options) {
|
|
|
347
701
|
};
|
|
348
702
|
}
|
|
349
703
|
//#endregion
|
|
350
|
-
export { addGlobalOptions as a, resolveProgramCredentials as c, validateSandboxName as i, renderTable as l, parseCreateSandboxOptions as n, addProfileCommands as o, parseRunOptions as r, isProfileCommand as s, optionalInteger as t };
|
|
704
|
+
export { addGlobalOptions as a, resolveProgramCredentials as c, Command as d, validateSandboxName as i, renderTable as l, parseCreateSandboxOptions as n, addProfileCommands as o, parseRunOptions as r, isProfileCommand as s, optionalInteger as t, spinner as u };
|