@kvbox/cli 0.5.29 → 0.5.31
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/dist/kvbox.js +234 -121
- package/dist/kvbox.js.map +1 -1
- package/package.json +1 -1
package/dist/kvbox.js
CHANGED
|
@@ -149,7 +149,7 @@ async function spin(message, work, opts = {}) {
|
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
// src/program.ts
|
|
152
|
-
import { Command as
|
|
152
|
+
import { Command as Command72 } from "commander";
|
|
153
153
|
|
|
154
154
|
// ../shared/src/version.ts
|
|
155
155
|
import { createRequire } from "module";
|
|
@@ -164,10 +164,10 @@ function versionOf(srcFileUrl, injected) {
|
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
// src/version.ts
|
|
167
|
-
var VERSION = versionOf(import.meta.url, true ? "0.5.
|
|
167
|
+
var VERSION = versionOf(import.meta.url, true ? "0.5.31" : void 0);
|
|
168
168
|
|
|
169
169
|
// src/commands/vm/index.ts
|
|
170
|
-
import { Command as
|
|
170
|
+
import { Command as Command33 } from "commander";
|
|
171
171
|
|
|
172
172
|
// src/commands/vm/connect.ts
|
|
173
173
|
import { spawnSync as spawnSync2 } from "child_process";
|
|
@@ -471,6 +471,21 @@ var DomainSchema = z2.object({
|
|
|
471
471
|
records: z2.array(z2.object({ type: z2.enum(["A", "TXT", "CNAME"]), name: z2.string(), value: z2.string() })),
|
|
472
472
|
createdAt: z2.string()
|
|
473
473
|
});
|
|
474
|
+
var WakeHookSchema = z2.object({
|
|
475
|
+
id: z2.string(),
|
|
476
|
+
owner: z2.string(),
|
|
477
|
+
box: z2.string(),
|
|
478
|
+
url: z2.string(),
|
|
479
|
+
createdBy: z2.string().nullable(),
|
|
480
|
+
createdAt: z2.string(),
|
|
481
|
+
lastCalledAt: z2.string().nullable()
|
|
482
|
+
});
|
|
483
|
+
var CreatedWakeHookSchema = WakeHookSchema.extend({ secret: z2.string() });
|
|
484
|
+
var WakeHookCallSchema = z2.object({
|
|
485
|
+
box: z2.string(),
|
|
486
|
+
action: z2.enum(["wake", "resume", "none"]),
|
|
487
|
+
reason: z2.string().optional()
|
|
488
|
+
});
|
|
474
489
|
var MachineSchema = z2.object({
|
|
475
490
|
/** Host-unique short id (the tap is `kv-<id>`). Missing only on a box made before ids that has not restarted since. */
|
|
476
491
|
id: z2.string(),
|
|
@@ -515,6 +530,8 @@ var MachineSchema = z2.object({
|
|
|
515
530
|
volumes: z2.array(z2.object({ name: z2.string(), sizeGib: z2.number().int(), mountPath: z2.string() })).optional(),
|
|
516
531
|
/** Boxes that may reach this one, each on one port (#98). Absent: none. */
|
|
517
532
|
links: z2.array(BoxLinkSchema).optional(),
|
|
533
|
+
/** How to reach what the box serves, its secrets masked (#87): `postgres://postgres:****@db.kvbox:5432/postgres`. */
|
|
534
|
+
url: z2.string().optional(),
|
|
518
535
|
/**
|
|
519
536
|
* Only in what `POST /machines` answers, for an image that declares one (#87): how to reach what it
|
|
520
537
|
* serves, e.g. `postgres://postgres:<password>@db.kvbox:5432/postgres`. Holds the box's variables.
|
|
@@ -1198,6 +1215,16 @@ var ServerClient = class {
|
|
|
1198
1215
|
removeLink(name, req) {
|
|
1199
1216
|
return this.call("DELETE", `/machines/${encodeURIComponent(name)}/links`, MachineSchema, req);
|
|
1200
1217
|
}
|
|
1218
|
+
/** Wake hooks (#101), the control plane's only: a URL and a secret that wake the box. */
|
|
1219
|
+
boxHooks(name) {
|
|
1220
|
+
return this.call("GET", `/machines/${encodeURIComponent(name)}/hooks`, z3.array(WakeHookSchema));
|
|
1221
|
+
}
|
|
1222
|
+
createBoxHook(name) {
|
|
1223
|
+
return this.call("POST", `/machines/${encodeURIComponent(name)}/hooks`, CreatedWakeHookSchema);
|
|
1224
|
+
}
|
|
1225
|
+
removeBoxHook(name, id) {
|
|
1226
|
+
return this.call("DELETE", `/machines/${encodeURIComponent(name)}/hooks/${encodeURIComponent(id)}`, WakeHookSchema);
|
|
1227
|
+
}
|
|
1201
1228
|
/** HTTPS names (#31), the control plane's only: the box's subdomain, claimed for its default port. */
|
|
1202
1229
|
claimSubdomain(name, req) {
|
|
1203
1230
|
return this.call("PUT", `/machines/${encodeURIComponent(name)}/subdomain`, SubdomainSchema, req);
|
|
@@ -1268,13 +1295,13 @@ var ServerClient = class {
|
|
|
1268
1295
|
// ---- environment variables (#88), a control plane only: the caller's slug, or `--org`'s ----
|
|
1269
1296
|
/** `org`: that org's list instead of `--org`'s (or the caller's own). */
|
|
1270
1297
|
listEnv(org) {
|
|
1271
|
-
return this.call("GET", "/
|
|
1298
|
+
return this.call("GET", "/vars", z3.array(EnvVarSchema), void 0, org);
|
|
1272
1299
|
}
|
|
1273
1300
|
setEnv(name, req) {
|
|
1274
|
-
return this.call("PUT", `/
|
|
1301
|
+
return this.call("PUT", `/vars/${encodeURIComponent(name)}`, EnvChangeSchema, req);
|
|
1275
1302
|
}
|
|
1276
1303
|
removeEnv(name) {
|
|
1277
|
-
return this.call("DELETE", `/
|
|
1304
|
+
return this.call("DELETE", `/vars/${encodeURIComponent(name)}`, EnvChangeSchema);
|
|
1278
1305
|
}
|
|
1279
1306
|
// ---- a box's own variables (#87), kept on its host, over its owner's at its next start ----
|
|
1280
1307
|
boxEnv(name) {
|
|
@@ -2084,13 +2111,14 @@ function getRows(box, sub, user) {
|
|
|
2084
2111
|
rows2.push(["address", box.ssh?.host ?? (box.ip === "" ? "-" : box.ip)]);
|
|
2085
2112
|
rows2.push(["ssh", box.ssh ? `ssh -p ${box.ssh.port} ${box.ssh.user}@${box.ssh.host}` : `kvbox connect ${displayName(box, user)}`]);
|
|
2086
2113
|
}
|
|
2114
|
+
if (box.url !== void 0) rows2.push(["connect", `${box.url} ${color.dim("(password shown once, at new)")}`]);
|
|
2087
2115
|
rows2.push(["url", sub ? [`${sub.url} ${color.dim(`(port ${sub.port})`)}`, ...sub.routes.map((r) => `${r.url} ${color.dim(`(port ${r.port})`)}`)].join(", ") : "-"]);
|
|
2088
2116
|
const ports = rowsOf(box, user).map((r) => `${r.guestPort}/${r.proto} \u2192 ${reaches(r, true)}`);
|
|
2089
2117
|
rows2.push(["ports", ports.length === 0 ? "-" : ports.join(", ")]);
|
|
2090
2118
|
rows2.push(["volumes", box.volumes?.length ? box.volumes.map((v) => `${v.name} ${color.dim(`(${v.sizeGib} GB at ${v.mountPath})`)}`).join(", ") : "-"]);
|
|
2091
2119
|
rows2.push(["auto-hibernate", box.autoHibernateSec ? `after ${duration(box.autoHibernateSec)} without network traffic` : "off"]);
|
|
2092
2120
|
rows2.push(["source", box.source]);
|
|
2093
|
-
rows2.push(["base", box.base]);
|
|
2121
|
+
rows2.push(["base", box.image === void 0 ? box.base : `${box.image} ${box.base}`]);
|
|
2094
2122
|
rows2.push(["created", `${age(box.createdAt)} ${color.dim(`(${box.createdAt})`)}`]);
|
|
2095
2123
|
return rows2;
|
|
2096
2124
|
}
|
|
@@ -2438,9 +2466,93 @@ var setPortCommand = new Command16("set-port").description("point a box's HTTPS
|
|
|
2438
2466
|
var proxyCommand = new Command17("proxy").description("publish box ports on the internet").addCommand(addCommand).addCommand(lsCommand2).addCommand(rmCommand).addCommand(claimCommand).addCommand(setPortCommand).addCommand(releaseCommand);
|
|
2439
2467
|
for (const cmd of proxyCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
2440
2468
|
|
|
2469
|
+
// src/commands/vm/hook/index.ts
|
|
2470
|
+
import { Command as Command21 } from "commander";
|
|
2471
|
+
|
|
2472
|
+
// src/commands/vm/hook/create.ts
|
|
2473
|
+
import { Command as Command18 } from "commander";
|
|
2474
|
+
|
|
2475
|
+
// src/commands/vm/hook/shared.ts
|
|
2476
|
+
function requireCloud2(client) {
|
|
2477
|
+
if (client.target.kind !== "cloud") throw new KvboxError("wake hooks need the kvbox cloud: kvbox login (this host's own socket has none)");
|
|
2478
|
+
}
|
|
2479
|
+
|
|
2480
|
+
// src/commands/vm/hook/create.ts
|
|
2481
|
+
var createCommand = new Command18("create").description("make a URL that wakes the box when called (a GitHub webhook, cron, any automation)").argument("<box>", "box name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
2482
|
+
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
2483
|
+
try {
|
|
2484
|
+
requireCloud2(client);
|
|
2485
|
+
const box = displayName(await findBox(client, name), me(client));
|
|
2486
|
+
const hook = await client.createBoxHook(box);
|
|
2487
|
+
if (opts.json) {
|
|
2488
|
+
json(hook);
|
|
2489
|
+
return;
|
|
2490
|
+
}
|
|
2491
|
+
info(`${color.green("\u2713")} hook ${hook.id} wakes box ${color.bold(box)}`);
|
|
2492
|
+
info(` url: ${hook.url}`);
|
|
2493
|
+
info(` secret: ${hook.secret} ${color.dim("(shown only now)")}`);
|
|
2494
|
+
info("");
|
|
2495
|
+
info(color.dim(" GitHub: repo Settings \u2192 Webhooks \u2192 Payload URL = the url, Content type = application/json,"));
|
|
2496
|
+
info(color.dim(" Secret = the secret, events: Workflow jobs."));
|
|
2497
|
+
info(color.dim(` anything else: curl -X POST -H "Authorization: Bearer <secret>" ${hook.url}`));
|
|
2498
|
+
info(color.dim(" A hibernated box wakes and a paused one resumes, at most once a minute; a stopped box stays stopped."));
|
|
2499
|
+
} finally {
|
|
2500
|
+
await client.close();
|
|
2501
|
+
}
|
|
2502
|
+
});
|
|
2503
|
+
|
|
2504
|
+
// src/commands/vm/hook/ls.ts
|
|
2505
|
+
import { Command as Command19 } from "commander";
|
|
2506
|
+
var lsCommand3 = new Command19("ls").alias("list").description("list a box's wake hooks").argument("<box>", "box name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
2507
|
+
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
2508
|
+
try {
|
|
2509
|
+
requireCloud2(client);
|
|
2510
|
+
const box = displayName(await findBox(client, name), me(client));
|
|
2511
|
+
const hooks = await client.boxHooks(box);
|
|
2512
|
+
if (opts.json) {
|
|
2513
|
+
json(hooks);
|
|
2514
|
+
return;
|
|
2515
|
+
}
|
|
2516
|
+
if (hooks.length === 0) {
|
|
2517
|
+
info(`box ${box} has no wake hooks; make one with: kvbox vm hook create ${box}`);
|
|
2518
|
+
return;
|
|
2519
|
+
}
|
|
2520
|
+
table(hooks.map((h) => ({ id: h.id, url: h.url, "last called": h.lastCalledAt ? age(h.lastCalledAt) : color.dim("never"), by: h.createdBy ?? "-", created: age(h.createdAt) })));
|
|
2521
|
+
} finally {
|
|
2522
|
+
await client.close();
|
|
2523
|
+
}
|
|
2524
|
+
});
|
|
2525
|
+
|
|
2526
|
+
// src/commands/vm/hook/rm.ts
|
|
2527
|
+
import { Command as Command20 } from "commander";
|
|
2528
|
+
var rmCommand2 = new Command20("rm").alias("remove").description("remove a wake hook: its URL stops working").argument("<box>", "box name").argument("<id>", "the hook's id (kvbox vm hook ls <box>)").option("-y, --yes", "do not ask for confirmation").option("--json", "print the removed hook as JSON").action(async (name, id, opts, cmd) => {
|
|
2529
|
+
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
2530
|
+
try {
|
|
2531
|
+
requireCloud2(client);
|
|
2532
|
+
const box = displayName(await findBox(client, name), me(client));
|
|
2533
|
+
if (!await confirm(`Remove hook ${id} of box ${box}? Whatever calls its URL stops waking the box.`, opts.yes ?? false)) {
|
|
2534
|
+
info("cancelled");
|
|
2535
|
+
process.exitCode = 1;
|
|
2536
|
+
return;
|
|
2537
|
+
}
|
|
2538
|
+
const hook = await client.removeBoxHook(box, id);
|
|
2539
|
+
if (opts.json) {
|
|
2540
|
+
json(hook);
|
|
2541
|
+
return;
|
|
2542
|
+
}
|
|
2543
|
+
info(`${color.green("\u2713")} hook ${hook.id} removed; its URL no longer wakes box ${color.bold(box)}`);
|
|
2544
|
+
} finally {
|
|
2545
|
+
await client.close();
|
|
2546
|
+
}
|
|
2547
|
+
});
|
|
2548
|
+
|
|
2549
|
+
// src/commands/vm/hook/index.ts
|
|
2550
|
+
var hookCommand = new Command21("hook").description("URLs that wake a box when called (GitHub webhooks, cron, any automation)").addCommand(createCommand).addCommand(lsCommand3).addCommand(rmCommand2);
|
|
2551
|
+
for (const cmd of hookCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
2552
|
+
|
|
2441
2553
|
// src/commands/vm/rescale.ts
|
|
2442
|
-
import { Command as
|
|
2443
|
-
var rescaleCommand = new
|
|
2554
|
+
import { Command as Command22, Option as Option3 } from "commander";
|
|
2555
|
+
var rescaleCommand = new Command22("rescale").description("change a box's vCPUs, memory or disk (e.g. --vcpu 4 --mem 16GB); a running box restarts").argument("<name>", "box name").addOption(new Option3("-s, --size <size>", "a preset to start from").choices(SIZE_NAMES)).option("--vcpu <n>", "number of vCPUs").option("--mem <size>", "memory, e.g. 16GB or 4096MB").option("--disk <size>", "disk size, e.g. 32GB (grow only)").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
2444
2556
|
const req = {
|
|
2445
2557
|
...opts.size !== void 0 ? { size: opts.size } : {},
|
|
2446
2558
|
...opts.vcpu !== void 0 ? { vcpu: parseCount(opts.vcpu) } : {},
|
|
@@ -2485,8 +2597,8 @@ function parseGib(flag, text2) {
|
|
|
2485
2597
|
}
|
|
2486
2598
|
|
|
2487
2599
|
// src/commands/vm/resume.ts
|
|
2488
|
-
import { Command as
|
|
2489
|
-
var resumeCommand = new
|
|
2600
|
+
import { Command as Command23 } from "commander";
|
|
2601
|
+
var resumeCommand = new Command23("resume").description("continue a box that is in standby (kvbox pause)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
2490
2602
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
2491
2603
|
try {
|
|
2492
2604
|
const box = await spin(`resuming ${name}\u2026`, client.resumeMachine(name));
|
|
@@ -2498,8 +2610,8 @@ var resumeCommand = new Command19("resume").description("continue a box that is
|
|
|
2498
2610
|
});
|
|
2499
2611
|
|
|
2500
2612
|
// src/commands/vm/rm.ts
|
|
2501
|
-
import { Command as
|
|
2502
|
-
var
|
|
2613
|
+
import { Command as Command24 } from "commander";
|
|
2614
|
+
var rmCommand3 = new Command24("rm").description("destroy a box (its disk is deleted; snapshots are kept)").argument("<name>", "box name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
|
|
2503
2615
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
2504
2616
|
try {
|
|
2505
2617
|
const box = pickRef(await boxesFor(client, name), name, me(client));
|
|
@@ -2519,8 +2631,8 @@ var rmCommand2 = new Command20("rm").description("destroy a box (its disk is del
|
|
|
2519
2631
|
});
|
|
2520
2632
|
|
|
2521
2633
|
// src/commands/vm/set.ts
|
|
2522
|
-
import { Command as
|
|
2523
|
-
var setCommand = new
|
|
2634
|
+
import { Command as Command25 } from "commander";
|
|
2635
|
+
var setCommand = new Command25("set").description("change a box's settings, e.g. --auto-hibernate 30m (off: never)").argument("<name>", "box name").option("--auto-hibernate <duration>", "hibernate the box after this long without network traffic (30m, 4h, 1d; off: never)").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
2524
2636
|
if (opts.autoHibernate === void 0) throw new KvboxError("nothing to change: give --auto-hibernate");
|
|
2525
2637
|
const autoHibernateSec = parseIdleTimeout(opts.autoHibernate);
|
|
2526
2638
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
@@ -2539,8 +2651,8 @@ var setCommand = new Command21("set").description("change a box's settings, e.g.
|
|
|
2539
2651
|
});
|
|
2540
2652
|
|
|
2541
2653
|
// src/commands/vm/start.ts
|
|
2542
|
-
import { Command as
|
|
2543
|
-
var startCommand = new
|
|
2654
|
+
import { Command as Command26 } from "commander";
|
|
2655
|
+
var startCommand = new Command26("start").description("boot a stopped box again (same name, IP and disk)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
2544
2656
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
2545
2657
|
try {
|
|
2546
2658
|
const box = await spin(`booting ${name}\u2026`, client.startMachine(name));
|
|
@@ -2552,8 +2664,8 @@ var startCommand = new Command22("start").description("boot a stopped box again
|
|
|
2552
2664
|
});
|
|
2553
2665
|
|
|
2554
2666
|
// src/commands/vm/stop.ts
|
|
2555
|
-
import { Command as
|
|
2556
|
-
var stopCommand = new
|
|
2667
|
+
import { Command as Command27 } from "commander";
|
|
2668
|
+
var stopCommand = new Command27("stop").description("shut a box down (its disk is kept; start it again with kvbox start)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
2557
2669
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
2558
2670
|
try {
|
|
2559
2671
|
const box = await spin(`shutting ${name} down\u2026`, client.stopMachine(name));
|
|
@@ -2565,8 +2677,8 @@ var stopCommand = new Command23("stop").description("shut a box down (its disk i
|
|
|
2565
2677
|
});
|
|
2566
2678
|
|
|
2567
2679
|
// src/commands/vm/top.ts
|
|
2568
|
-
import { Command as
|
|
2569
|
-
var topCommand = new
|
|
2680
|
+
import { Command as Command28 } from "commander";
|
|
2681
|
+
var topCommand = new Command28("top").description("load, memory and disk of each running box, as the box itself sees them").option("-a, --all", "every running box on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
2570
2682
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
2571
2683
|
try {
|
|
2572
2684
|
const running = (await client.listMachines({ all: opts.all })).filter((b) => b.status === "running");
|
|
@@ -2626,8 +2738,8 @@ function topRows(entries, cloud) {
|
|
|
2626
2738
|
}
|
|
2627
2739
|
|
|
2628
2740
|
// src/commands/vm/unlink.ts
|
|
2629
|
-
import { Command as
|
|
2630
|
-
var unlinkCommand = new
|
|
2741
|
+
import { Command as Command29 } from "commander";
|
|
2742
|
+
var unlinkCommand = new Command29("unlink").description("take a link away (kvbox vm link)").argument("<from>", "the box that connects").argument("<box>", "the box it reaches").requiredOption("-p, --port <port>", "the port in <box>").option("-y, --yes", "do not ask for confirmation").option("--json", "print the removed link as JSON").action(async (from, name, opts, cmd) => {
|
|
2631
2743
|
const port = parseLinkPort(opts.port);
|
|
2632
2744
|
if (!await confirm(`Cut box ${from} off from box ${name} port ${port}? Its open connections close too.`, opts.yes ?? false)) {
|
|
2633
2745
|
info("cancelled");
|
|
@@ -2648,8 +2760,8 @@ var unlinkCommand = new Command25("unlink").description("take a link away (kvbox
|
|
|
2648
2760
|
});
|
|
2649
2761
|
|
|
2650
2762
|
// src/commands/vm/update.ts
|
|
2651
|
-
import { Command as
|
|
2652
|
-
var updateCommand = new
|
|
2763
|
+
import { Command as Command30 } from "commander";
|
|
2764
|
+
var updateCommand = new Command30("update").description("move a box onto the current base image (its files stay; a running box restarts)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
2653
2765
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
2654
2766
|
try {
|
|
2655
2767
|
const before = pickRef(await boxesFor(client, name), name, me(client));
|
|
@@ -2671,8 +2783,8 @@ var updateCommand = new Command26("update").description("move a box onto the cur
|
|
|
2671
2783
|
});
|
|
2672
2784
|
|
|
2673
2785
|
// src/commands/vm/usage.ts
|
|
2674
|
-
import { Command as
|
|
2675
|
-
var usageCommand = new
|
|
2786
|
+
import { Command as Command31 } from "commander";
|
|
2787
|
+
var usageCommand = new Command31("usage").description("how long a box ran, slept and sat stopped, as vCPU-hours, RAM and disk GiB-hours (and cost, when the host prices them)").argument("<name>", "box name").option("--since <date>", "count from this date instead of the box's creation, e.g. 2026-10-01").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
2676
2788
|
let since;
|
|
2677
2789
|
if (opts.since !== void 0) {
|
|
2678
2790
|
const t = Date.parse(opts.since);
|
|
@@ -2719,8 +2831,8 @@ function block(u) {
|
|
|
2719
2831
|
}
|
|
2720
2832
|
|
|
2721
2833
|
// src/commands/vm/wake.ts
|
|
2722
|
-
import { Command as
|
|
2723
|
-
var wakeCommand = new
|
|
2834
|
+
import { Command as Command32 } from "commander";
|
|
2835
|
+
var wakeCommand = new Command32("wake").description("continue a hibernated box where it left off (same name, IP and disk)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
2724
2836
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
2725
2837
|
try {
|
|
2726
2838
|
const box = await spin(`waking ${name} (loading its memory from disk)\u2026`, client.wakeMachine(name));
|
|
@@ -2732,15 +2844,15 @@ var wakeCommand = new Command28("wake").description("continue a hibernated box w
|
|
|
2732
2844
|
});
|
|
2733
2845
|
|
|
2734
2846
|
// src/commands/vm/index.ts
|
|
2735
|
-
var vmCommand = new
|
|
2736
|
-
for (const cmd of vmCommand.commands) if (cmd !== proxyCommand) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
2737
|
-
var vmAliases = [newCommand, lsCommand, getCommand, connectCommand, execCommand, stopCommand, startCommand, pauseCommand, resumeCommand, hibernateCommand, wakeCommand,
|
|
2847
|
+
var vmCommand = new Command33("vm").enablePositionalOptions().description("manage boxes (each one is a Firecracker microVM)").addCommand(newCommand).addCommand(forkCommand).addCommand(lsCommand).addCommand(getCommand).addCommand(connectCommand).addCommand(execCommand).addCommand(stopCommand).addCommand(startCommand).addCommand(pauseCommand).addCommand(resumeCommand).addCommand(hibernateCommand).addCommand(wakeCommand).addCommand(updateCommand).addCommand(rescaleCommand).addCommand(setCommand).addCommand(usageCommand).addCommand(topCommand).addCommand(proxyCommand).addCommand(hookCommand).addCommand(linkCommand).addCommand(unlinkCommand).addCommand(linksCommand).addCommand(rmCommand3);
|
|
2848
|
+
for (const cmd of vmCommand.commands) if (cmd !== proxyCommand && cmd !== hookCommand) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
2849
|
+
var vmAliases = [newCommand, lsCommand, getCommand, connectCommand, execCommand, stopCommand, startCommand, pauseCommand, resumeCommand, hibernateCommand, wakeCommand, rmCommand3, claimCommand];
|
|
2738
2850
|
|
|
2739
2851
|
// src/commands/server/index.ts
|
|
2740
|
-
import { Command as
|
|
2852
|
+
import { Command as Command41 } from "commander";
|
|
2741
2853
|
|
|
2742
2854
|
// src/commands/server/join.ts
|
|
2743
|
-
import { Command as
|
|
2855
|
+
import { Command as Command34 } from "commander";
|
|
2744
2856
|
|
|
2745
2857
|
// src/commands/server/daemon.ts
|
|
2746
2858
|
import { spawn as spawn3 } from "child_process";
|
|
@@ -2794,7 +2906,7 @@ function runKvboxServer(args) {
|
|
|
2794
2906
|
}
|
|
2795
2907
|
|
|
2796
2908
|
// src/commands/server/join.ts
|
|
2797
|
-
var joinCommand = new
|
|
2909
|
+
var joinCommand = new Command34("join").description("put this machine behind a control plane (needs a one-time token minted there) and restart its server").argument("<control-plane-url>", "the control plane, e.g. https://api.kvbox.sh").requiredOption("--token <token>", "one-time join token from the control plane").option("--advertise <host-or-ip>", "address the control plane reaches this machine at (default: its default-route address)").option("--name <name>", "how the control plane lists this machine (default: hostname)").action(async (url, opts) => {
|
|
2798
2910
|
const args = ["join", url, "--token", opts.token];
|
|
2799
2911
|
if (opts.advertise !== void 0) args.push("--advertise", opts.advertise);
|
|
2800
2912
|
if (opts.name !== void 0) args.push("--name", opts.name);
|
|
@@ -2804,8 +2916,8 @@ var joinCommand = new Command30("join").description("put this machine behind a c
|
|
|
2804
2916
|
});
|
|
2805
2917
|
|
|
2806
2918
|
// src/commands/server/leave.ts
|
|
2807
|
-
import { Command as
|
|
2808
|
-
var leaveCommand = new
|
|
2919
|
+
import { Command as Command35 } from "commander";
|
|
2920
|
+
var leaveCommand = new Command35("leave").description("take this machine out from behind its control plane and restart its server").action(async () => {
|
|
2809
2921
|
const p = paths();
|
|
2810
2922
|
for (const line of (await runKvboxServer(["leave"])).split("\n")) info(line);
|
|
2811
2923
|
if (await runningPid(p) === null) return;
|
|
@@ -2814,14 +2926,14 @@ var leaveCommand = new Command31("leave").description("take this machine out fro
|
|
|
2814
2926
|
});
|
|
2815
2927
|
|
|
2816
2928
|
// src/commands/server/relay.ts
|
|
2817
|
-
import { Command as
|
|
2818
|
-
var relayCommand = new
|
|
2929
|
+
import { Command as Command36 } from "commander";
|
|
2930
|
+
var relayCommand = new Command36("relay").description("reach the internet through a relay (paste what `kvbox-relay add` printed on the relay VM); `off` takes the tunnel down").argument("<join-string>", "the line `kvbox-relay add` printed, or `off`").action(async (joinString) => {
|
|
2819
2931
|
for (const line of (await runKvboxServer(["relay", joinString])).split("\n")) info(line);
|
|
2820
2932
|
});
|
|
2821
2933
|
|
|
2822
2934
|
// src/commands/server/start.ts
|
|
2823
|
-
import { Command as
|
|
2824
|
-
var startCommand2 = new
|
|
2935
|
+
import { Command as Command37 } from "commander";
|
|
2936
|
+
var startCommand2 = new Command37("start").description("start the local kvbox-server in the background").action(async (_opts, cmd) => {
|
|
2825
2937
|
const client = await clientFor({ ...cmd.optsWithGlobals(), local: true }, { autoStart: false });
|
|
2826
2938
|
try {
|
|
2827
2939
|
const health = await client.health();
|
|
@@ -2837,8 +2949,8 @@ var startCommand2 = new Command33("start").description("start the local kvbox-se
|
|
|
2837
2949
|
});
|
|
2838
2950
|
|
|
2839
2951
|
// src/commands/server/status.ts
|
|
2840
|
-
import { Command as
|
|
2841
|
-
var statusCommand = new
|
|
2952
|
+
import { Command as Command38 } from "commander";
|
|
2953
|
+
var statusCommand = new Command38("status").description("show whether this machine's server is running, its control plane and which base image new boxes get").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
2842
2954
|
const client = await clientFor({ ...cmd.optsWithGlobals(), local: true });
|
|
2843
2955
|
try {
|
|
2844
2956
|
const health = await client.health();
|
|
@@ -2870,8 +2982,8 @@ var statusCommand = new Command34("status").description("show whether this machi
|
|
|
2870
2982
|
});
|
|
2871
2983
|
|
|
2872
2984
|
// src/commands/server/stop.ts
|
|
2873
|
-
import { Command as
|
|
2874
|
-
var stopCommand2 = new
|
|
2985
|
+
import { Command as Command39 } from "commander";
|
|
2986
|
+
var stopCommand2 = new Command39("stop").description("stop the local server (running boxes are not affected)").action(async () => {
|
|
2875
2987
|
const pid = await runningPid(paths());
|
|
2876
2988
|
if (pid === null) throw new KvboxError("kvbox-server is not running");
|
|
2877
2989
|
await stopLocalServer(pid);
|
|
@@ -2879,8 +2991,8 @@ var stopCommand2 = new Command35("stop").description("stop the local server (run
|
|
|
2879
2991
|
});
|
|
2880
2992
|
|
|
2881
2993
|
// src/commands/server/trust-ca.ts
|
|
2882
|
-
import { Command as
|
|
2883
|
-
var trustCaCommand = new
|
|
2994
|
+
import { Command as Command40 } from "commander";
|
|
2995
|
+
var trustCaCommand = new Command40("trust-ca").description("make every cloud box on this machine trust a new SSH CA (after `ca rotate` on the control plane)").argument("[public-key]", "the CA public key (or its cert-authority line); or --from-cloud").option("--from-cloud", "ask the control plane this host joined for its current CA, show the fingerprint, then ask").option("-y, --yes", "do not ask for confirmation").option("--json", "print the report as JSON").action(async (publicKey, opts, cmd) => {
|
|
2884
2996
|
if (publicKey === void 0 && !opts.fromCloud) throw new KvboxError("give the CA public key, or --from-cloud to fetch it from the control plane this host joined");
|
|
2885
2997
|
if (publicKey !== void 0 && opts.fromCloud) throw new KvboxError("either a public key or --from-cloud, not both");
|
|
2886
2998
|
const client = await clientFor({ ...cmd.optsWithGlobals(), local: true });
|
|
@@ -2918,7 +3030,7 @@ function describeReport(report) {
|
|
|
2918
3030
|
}
|
|
2919
3031
|
|
|
2920
3032
|
// src/commands/server/index.ts
|
|
2921
|
-
var serverCommand = new
|
|
3033
|
+
var serverCommand = new Command41("server").description("run or manage the kvbox server").addCommand(startCommand2).addCommand(statusCommand).addCommand(stopCommand2).addCommand(joinCommand).addCommand(leaveCommand).addCommand(relayCommand).addCommand(trustCaCommand);
|
|
2922
3034
|
|
|
2923
3035
|
// src/commands/login.ts
|
|
2924
3036
|
import { spawnSync as spawnSync3 } from "child_process";
|
|
@@ -2926,8 +3038,8 @@ import { mkdir as mkdir3, readFile as readFile5, writeFile as writeFile3 } from
|
|
|
2926
3038
|
import { hostname as osHostname } from "os";
|
|
2927
3039
|
import { createInterface as createInterface2 } from "readline/promises";
|
|
2928
3040
|
import { Writable } from "stream";
|
|
2929
|
-
import { Command as
|
|
2930
|
-
var loginCommand = new
|
|
3041
|
+
import { Command as Command42 } from "commander";
|
|
3042
|
+
var loginCommand = new Command42("login").description("log in to the kvbox cloud (or your own control plane) and target it from now on").argument("[url]", `control plane URL (default: ${DEFAULT_CLOUD_URL})`).option("-e, --email <email>", "account email (prompted otherwise)").option("--password-stdin", "read the password from the first line of stdin (for scripts)").action(async (urlArg, opts) => {
|
|
2931
3043
|
const url = normalizeUrl(urlArg ?? DEFAULT_CLOUD_URL);
|
|
2932
3044
|
const creds = await readCredentials(opts);
|
|
2933
3045
|
const session = await runLogin(url, creds, paths());
|
|
@@ -3007,8 +3119,8 @@ async function firstLine(stream) {
|
|
|
3007
3119
|
}
|
|
3008
3120
|
|
|
3009
3121
|
// src/commands/logout.ts
|
|
3010
|
-
import { Command as
|
|
3011
|
-
var logoutCommand = new
|
|
3122
|
+
import { Command as Command43 } from "commander";
|
|
3123
|
+
var logoutCommand = new Command43("logout").description("log out of the control plane; commands target this machine's kvbox-server again").action(async () => {
|
|
3012
3124
|
const p = paths();
|
|
3013
3125
|
const session = await readSession(p).catch(() => null);
|
|
3014
3126
|
switch (await runLogout(p)) {
|
|
@@ -3045,8 +3157,8 @@ async function runLogout(p = paths()) {
|
|
|
3045
3157
|
}
|
|
3046
3158
|
|
|
3047
3159
|
// src/commands/whoami.ts
|
|
3048
|
-
import { Command as
|
|
3049
|
-
var whoamiCommand = new
|
|
3160
|
+
import { Command as Command44 } from "commander";
|
|
3161
|
+
var whoamiCommand = new Command44("whoami").description("show which account and control plane commands target (or local mode)").option("--json", "print as JSON").action(async (opts) => {
|
|
3050
3162
|
const session = await readSession();
|
|
3051
3163
|
if (opts.json) {
|
|
3052
3164
|
json(session ? { user: session.user, url: session.url, sshCertExpires: session.sshCertExpires ?? null } : null);
|
|
@@ -3062,11 +3174,11 @@ function describeSession(session) {
|
|
|
3062
3174
|
}
|
|
3063
3175
|
|
|
3064
3176
|
// src/commands/snapshots/index.ts
|
|
3065
|
-
import { Command as
|
|
3177
|
+
import { Command as Command48 } from "commander";
|
|
3066
3178
|
|
|
3067
3179
|
// src/commands/snapshots/ls.ts
|
|
3068
|
-
import { Command as
|
|
3069
|
-
var
|
|
3180
|
+
import { Command as Command45 } from "commander";
|
|
3181
|
+
var lsCommand4 = new Command45("ls").description("list snapshots (yours and your orgs'; --org <slug> for one org)").option("-a, --all", "every snapshot on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
3070
3182
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
3071
3183
|
try {
|
|
3072
3184
|
const cloud = client.target.kind === "cloud";
|
|
@@ -3097,8 +3209,8 @@ var lsCommand3 = new Command41("ls").description("list snapshots (yours and your
|
|
|
3097
3209
|
});
|
|
3098
3210
|
|
|
3099
3211
|
// src/commands/snapshots/new.ts
|
|
3100
|
-
import { Command as
|
|
3101
|
-
var newCommand2 = new
|
|
3212
|
+
import { Command as Command46 } from "commander";
|
|
3213
|
+
var newCommand2 = new Command46("new").description("freeze a running box (memory + disk) into a snapshot; the box keeps running").argument("<box>", "box name").argument("<name>", "snapshot name").option("--replace", "retake a snapshot that exists under this name; the old one stays until the new one is complete").option("--json", "print the snapshot as JSON").action(async (box, name, opts, cmd) => {
|
|
3102
3214
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
3103
3215
|
try {
|
|
3104
3216
|
const req = { box, name, ...opts.replace ? { replace: true } : {} };
|
|
@@ -3111,8 +3223,8 @@ var newCommand2 = new Command42("new").description("freeze a running box (memory
|
|
|
3111
3223
|
});
|
|
3112
3224
|
|
|
3113
3225
|
// src/commands/snapshots/rm.ts
|
|
3114
|
-
import { Command as
|
|
3115
|
-
var
|
|
3226
|
+
import { Command as Command47 } from "commander";
|
|
3227
|
+
var rmCommand4 = new Command47("rm").description("delete a snapshot (boxes made from it are not affected)").argument("<name>", "snapshot name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
|
|
3116
3228
|
if (!await confirm(`Delete snapshot ${name}?`, opts.yes ?? false)) {
|
|
3117
3229
|
info("cancelled");
|
|
3118
3230
|
process.exitCode = 1;
|
|
@@ -3128,14 +3240,14 @@ var rmCommand3 = new Command43("rm").description("delete a snapshot (boxes made
|
|
|
3128
3240
|
});
|
|
3129
3241
|
|
|
3130
3242
|
// src/commands/snapshots/index.ts
|
|
3131
|
-
var snapshotsCommand = new
|
|
3243
|
+
var snapshotsCommand = new Command48("snapshots").aliases(["snapshot", "snap"]).description("freeze running boxes into snapshots and manage them").addCommand(newCommand2).addCommand(lsCommand4).addCommand(rmCommand4);
|
|
3132
3244
|
for (const cmd of snapshotsCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
3133
3245
|
|
|
3134
3246
|
// src/commands/org/index.ts
|
|
3135
|
-
import { Command as
|
|
3247
|
+
import { Command as Command54 } from "commander";
|
|
3136
3248
|
|
|
3137
3249
|
// src/commands/org/ls.ts
|
|
3138
|
-
import { Command as
|
|
3250
|
+
import { Command as Command49 } from "commander";
|
|
3139
3251
|
|
|
3140
3252
|
// src/commands/org/context.ts
|
|
3141
3253
|
var NOT_LOGGED_IN = "orgs live on the control plane: kvbox login first";
|
|
@@ -3155,7 +3267,7 @@ function orgFor(opts, target) {
|
|
|
3155
3267
|
}
|
|
3156
3268
|
|
|
3157
3269
|
// src/commands/org/ls.ts
|
|
3158
|
-
var
|
|
3270
|
+
var lsCommand5 = new Command49("ls").description("list the orgs you belong to and your role in each").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
3159
3271
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
3160
3272
|
try {
|
|
3161
3273
|
const orgs = await client.listOrgs();
|
|
@@ -3177,8 +3289,8 @@ function orgRows(orgs) {
|
|
|
3177
3289
|
}
|
|
3178
3290
|
|
|
3179
3291
|
// src/commands/org/members.ts
|
|
3180
|
-
import { Command as
|
|
3181
|
-
var
|
|
3292
|
+
import { Command as Command50, Option as Option4 } from "commander";
|
|
3293
|
+
var lsCommand6 = new Command50("ls").description("list an org's members and their roles").option("-o, --org <slug>", "the org (or --org before the command)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
3182
3294
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
3183
3295
|
try {
|
|
3184
3296
|
const org = await client.getOrg(orgFor(opts, client.target));
|
|
@@ -3192,7 +3304,7 @@ var lsCommand5 = new Command46("ls").description("list an org's members and thei
|
|
|
3192
3304
|
await client.close();
|
|
3193
3305
|
}
|
|
3194
3306
|
});
|
|
3195
|
-
var addCommand2 = new
|
|
3307
|
+
var addCommand2 = new Command50("add").description("add a user to an org (admins and owners; only an owner can add an owner)").argument("<user>", "their username").addOption(new Option4("-r, --role <role>", "their role").choices(ORG_ROLES).default("member")).option("-o, --org <slug>", "the org (or --org before the command)").action(async (user, opts, cmd) => {
|
|
3196
3308
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
3197
3309
|
try {
|
|
3198
3310
|
const slug = orgFor(opts, client.target);
|
|
@@ -3202,7 +3314,7 @@ var addCommand2 = new Command46("add").description("add a user to an org (admins
|
|
|
3202
3314
|
await client.close();
|
|
3203
3315
|
}
|
|
3204
3316
|
});
|
|
3205
|
-
var
|
|
3317
|
+
var rmCommand5 = new Command50("rm").description("remove a member (or leave: remove yourself)").argument("<user>", "their username").option("-o, --org <slug>", "the org (or --org before the command)").option("-y, --yes", "do not ask for confirmation").action(async (user, opts, cmd) => {
|
|
3206
3318
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
3207
3319
|
try {
|
|
3208
3320
|
const slug = orgFor(opts, client.target);
|
|
@@ -3218,11 +3330,11 @@ var rmCommand4 = new Command46("rm").description("remove a member (or leave: rem
|
|
|
3218
3330
|
await client.close();
|
|
3219
3331
|
}
|
|
3220
3332
|
});
|
|
3221
|
-
var membersCommand = new
|
|
3333
|
+
var membersCommand = new Command50("members").description("who is in an org and what they may do").addCommand(lsCommand6).addCommand(addCommand2).addCommand(rmCommand5);
|
|
3222
3334
|
|
|
3223
3335
|
// src/commands/org/new.ts
|
|
3224
|
-
import { Command as
|
|
3225
|
-
var newCommand3 = new
|
|
3336
|
+
import { Command as Command51 } from "commander";
|
|
3337
|
+
var newCommand3 = new Command51("new").description("create an org; you become its owner (the slug is permanent, the name is not)").argument("<slug>", "the org's slug: lowercase, like a username (acme)").option("-n, --name <name>", "display name (default: the slug)").option("--json", "print the org as JSON").action(async (slug, opts, cmd) => {
|
|
3226
3338
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
3227
3339
|
try {
|
|
3228
3340
|
const org = await client.createOrg({ slug, name: opts.name ?? slug });
|
|
@@ -3238,8 +3350,8 @@ var newCommand3 = new Command47("new").description("create an org; you become it
|
|
|
3238
3350
|
});
|
|
3239
3351
|
|
|
3240
3352
|
// src/commands/org/rm.ts
|
|
3241
|
-
import { Command as
|
|
3242
|
-
var
|
|
3353
|
+
import { Command as Command52 } from "commander";
|
|
3354
|
+
var rmCommand6 = new Command52("rm").description("delete an org (owners only; remove its boxes and snapshots first)").argument("<slug>", "the org").option("-y, --yes", "do not ask for confirmation").action(async (slug, opts, cmd) => {
|
|
3243
3355
|
if (!await confirm(`Delete org ${slug}? Its members lose access; its slug stays taken.`, opts.yes ?? false)) {
|
|
3244
3356
|
info("cancelled");
|
|
3245
3357
|
process.exitCode = 1;
|
|
@@ -3255,8 +3367,8 @@ var rmCommand5 = new Command48("rm").description("delete an org (owners only; re
|
|
|
3255
3367
|
});
|
|
3256
3368
|
|
|
3257
3369
|
// src/commands/org/role.ts
|
|
3258
|
-
import { Argument, Command as
|
|
3259
|
-
var roleCommand = new
|
|
3370
|
+
import { Argument, Command as Command53 } from "commander";
|
|
3371
|
+
var roleCommand = new Command53("role").description("change a member's role (owners only)").argument("<user>", "their username").addArgument(new Argument("<role>", "owner, admin or member").choices(ORG_ROLES)).option("-o, --org <slug>", "the org (default: the current context)").action(async (user, role, opts, cmd) => {
|
|
3260
3372
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
3261
3373
|
try {
|
|
3262
3374
|
const slug = orgFor(opts, client.target);
|
|
@@ -3268,10 +3380,10 @@ var roleCommand = new Command49("role").description("change a member's role (own
|
|
|
3268
3380
|
});
|
|
3269
3381
|
|
|
3270
3382
|
// src/commands/org/index.ts
|
|
3271
|
-
var orgCommand = new
|
|
3383
|
+
var orgCommand = new Command54("org").description("orgs: shared slugs that own boxes, with owners, admins and members").addCommand(lsCommand5).addCommand(newCommand3).addCommand(membersCommand).addCommand(roleCommand).addCommand(rmCommand6);
|
|
3272
3384
|
|
|
3273
3385
|
// src/commands/usage.ts
|
|
3274
|
-
import { Command as
|
|
3386
|
+
import { Command as Command55 } from "commander";
|
|
3275
3387
|
|
|
3276
3388
|
// ../shared/src/usage.ts
|
|
3277
3389
|
import { z as z4 } from "zod";
|
|
@@ -3281,7 +3393,8 @@ var PricingSchema = z4.object({
|
|
|
3281
3393
|
ramGibHour: z4.number().nonnegative(),
|
|
3282
3394
|
diskGibHour: z4.number().nonnegative(),
|
|
3283
3395
|
volumeHour: z4.number().nonnegative().default(0),
|
|
3284
|
-
volumeGibHour: z4.number().nonnegative().default(0)
|
|
3396
|
+
volumeGibHour: z4.number().nonnegative().default(0),
|
|
3397
|
+
diskIncludedGib: z4.number().int().nonnegative().default(0)
|
|
3285
3398
|
});
|
|
3286
3399
|
var round = (n, places) => Math.round(n * 10 ** places) / 10 ** places;
|
|
3287
3400
|
function costOf(t, pricing) {
|
|
@@ -3308,7 +3421,7 @@ function sumUsage(items, pricing) {
|
|
|
3308
3421
|
}
|
|
3309
3422
|
|
|
3310
3423
|
// src/commands/usage.ts
|
|
3311
|
-
var usageCommand2 = new
|
|
3424
|
+
var usageCommand2 = new Command55("usage").description("what your boxes and volumes used this month (or --since/--until): running time, vCPU-h, RAM and disk GiB-h, cost").option("--since <date>", "count from this date, e.g. 2026-10-01 (default: the 1st of this month)").option("--until <date>", "count up to this date (default: now)").option("--org <slug>", "one org's boxes only").option("-a, --all", "every box on the platform (platform admins only)").option("--by-user", "one line per user who made the boxes (e.g. who spent what in --org)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
3312
3425
|
for (const [name, value] of [
|
|
3313
3426
|
["since", opts.since],
|
|
3314
3427
|
["until", opts.until]
|
|
@@ -3454,8 +3567,8 @@ function userRows(r) {
|
|
|
3454
3567
|
}
|
|
3455
3568
|
|
|
3456
3569
|
// src/commands/credit.ts
|
|
3457
|
-
import { Command as
|
|
3458
|
-
var creditCommand = new
|
|
3570
|
+
import { Command as Command56 } from "commander";
|
|
3571
|
+
var creditCommand = new Command56("credit").description("the prepaid credit left on your account and on each of your orgs").option("--org <slug>", "one org only").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
3459
3572
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
3460
3573
|
try {
|
|
3461
3574
|
if (client.target.kind === "local") throw new KvboxError("credit lives on the control plane: kvbox login first");
|
|
@@ -3485,7 +3598,7 @@ function creditRow(b, me2) {
|
|
|
3485
3598
|
// src/commands/deploy/index.ts
|
|
3486
3599
|
import { readFile as readFile7 } from "fs/promises";
|
|
3487
3600
|
import { basename, resolve as resolve2 } from "path";
|
|
3488
|
-
import { Command as
|
|
3601
|
+
import { Command as Command57, InvalidArgumentError as InvalidArgumentError2, Option as Option5 } from "commander";
|
|
3489
3602
|
|
|
3490
3603
|
// src/commands/deploy/config.ts
|
|
3491
3604
|
import { readFile as readFile6, writeFile as writeFile4 } from "fs/promises";
|
|
@@ -3813,7 +3926,7 @@ async function ship(ep, dir, remote, exclude = []) {
|
|
|
3813
3926
|
var shipping = { ship, measure, waitForSsh };
|
|
3814
3927
|
|
|
3815
3928
|
// src/commands/deploy/index.ts
|
|
3816
|
-
var deployCommand = new
|
|
3929
|
+
var deployCommand = new Command57("deploy").description("put the app in this directory (React, Next.js or a Node server) on a box with its own HTTPS address; redeploy by running it again").argument("[dir]", "the app's directory (default: the current one)").addOption(new Option5("-t, --template <template>", "what kind of app it is (detected from package.json when not given)").choices(TEMPLATE_IDS)).option("-n, --name <name>", "the box's name (default: the directory's name)").option("--sub <subdomain>", "its HTTPS name, https://<subdomain>.kvbox.app (default: the box's name)").addOption(new Option5("-s, --size <size>", "size of the box when it has to be made").choices(SIZE_NAMES)).option("--port <port>", "the port a Node server listens on, when it does not use $PORT (default 3000; saved to kvbox.json)", parsePort).option("-y, --yes", "ask nothing: take the defaults for whatever the flags and kvbox.json leave open").option("--json", "print the result as JSON").option("--org <slug>", "deploy into this org's boxes (saved to kvbox.json)").action(async (dirArg, opts, cmd) => {
|
|
3817
3930
|
const dir = resolve2(dirArg ?? ".");
|
|
3818
3931
|
const pkg = await readPackageJson(dir);
|
|
3819
3932
|
const saved = await readConfig(dir);
|
|
@@ -4010,15 +4123,15 @@ the app is on box ${ref} but has no address yet: pick another with kvbox deploy
|
|
|
4010
4123
|
}
|
|
4011
4124
|
|
|
4012
4125
|
// src/commands/volume/index.ts
|
|
4013
|
-
import { Command as
|
|
4126
|
+
import { Command as Command63 } from "commander";
|
|
4014
4127
|
|
|
4015
4128
|
// src/commands/volume/attach.ts
|
|
4016
|
-
import { Command as
|
|
4129
|
+
import { Command as Command58 } from "commander";
|
|
4017
4130
|
function describeMount(machine, volume, box) {
|
|
4018
4131
|
const path = machine.volumes?.find((v) => volume === v.name || volume.endsWith(`/${v.name}`))?.mountPath ?? volumeMountPath(volume.slice(volume.lastIndexOf("/") + 1));
|
|
4019
4132
|
return machine.status === "running" ? ` the box was restarted; the volume is at ${path} inside it` : ` box ${box} is ${machine.status}; the volume is at ${path} once it runs`;
|
|
4020
4133
|
}
|
|
4021
|
-
var attachCommand = new
|
|
4134
|
+
var attachCommand = new Command58("attach").description("attach a volume to a box at /mnt/<volume> (a running box is restarted to take it)").argument("[volume]", "volume name (picked from a list when left out)").argument("[box]", "box name (picked from a list when left out)").option("--json", "print the box as JSON").action(async (volumeArg, boxArg, opts, cmd) => {
|
|
4022
4135
|
if (volumeArg === void 0 || boxArg === void 0) askOrUsage("give the volume and the box: kvbox volume attach <volume> <box>");
|
|
4023
4136
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4024
4137
|
try {
|
|
@@ -4037,7 +4150,7 @@ var attachCommand = new Command54("attach").description("attach a volume to a bo
|
|
|
4037
4150
|
});
|
|
4038
4151
|
|
|
4039
4152
|
// src/commands/volume/create.ts
|
|
4040
|
-
import { Command as
|
|
4153
|
+
import { Command as Command59 } from "commander";
|
|
4041
4154
|
function parseGib2(text2) {
|
|
4042
4155
|
const mib = parseMib(text2);
|
|
4043
4156
|
if (mib === void 0 || mib % 1024 !== 0) throw new KvboxError(`--size ${text2}: write whole GB, like 50 or 50GB`);
|
|
@@ -4053,7 +4166,7 @@ function sizeProblem(answer) {
|
|
|
4053
4166
|
return err instanceof KvboxError ? err.message.replace(/^--size \S+: /, "") : String(err);
|
|
4054
4167
|
}
|
|
4055
4168
|
}
|
|
4056
|
-
var
|
|
4169
|
+
var createCommand2 = new Command59("create").alias("new").description("create a volume for a box: an empty disk of its own at /mnt/<name> inside it (a running box is restarted)").argument("[name]", "volume name (1-12 chars; the box mounts it at /mnt/<name>; asked for when left out)").option("--size <gb>", "size in GB, like 50 or 50GB (whole GB; it only occupies what is written)").option("--box <box>", "the box it is for: made on that box's host and attached to it (required on kvbox.sh; optional with --local)").option("--json", "print the volume as JSON").action(async (nameArg, opts, cmd) => {
|
|
4057
4170
|
const ask = interactive();
|
|
4058
4171
|
if (nameArg === void 0 || opts.size === void 0) askOrUsage("give the name and the size: kvbox volume create <name> --size <gb> --box <box>");
|
|
4059
4172
|
const name = nameArg ?? await text("Volume name", { validate: (a) => VOLUME_NAME_RE.test(a) ? void 0 : VOLUME_NAME_RULE });
|
|
@@ -4086,8 +4199,8 @@ var createCommand = new Command55("create").alias("new").description("create a v
|
|
|
4086
4199
|
});
|
|
4087
4200
|
|
|
4088
4201
|
// src/commands/volume/detach.ts
|
|
4089
|
-
import { Command as
|
|
4090
|
-
var detachCommand = new
|
|
4202
|
+
import { Command as Command60 } from "commander";
|
|
4203
|
+
var detachCommand = new Command60("detach").description("detach a volume from a box; its data is kept (a running box is restarted)").argument("[volume]", "volume name (picked from a list when left out)").argument("[box]", "box name (the one the volume is on when left out)").option("--json", "print the box as JSON").action(async (volumeArg, boxArg, opts, cmd) => {
|
|
4091
4204
|
if (volumeArg === void 0) askOrUsage("give the volume: kvbox volume detach <volume> [box]");
|
|
4092
4205
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4093
4206
|
try {
|
|
@@ -4112,8 +4225,8 @@ var detachCommand = new Command56("detach").description("detach a volume from a
|
|
|
4112
4225
|
});
|
|
4113
4226
|
|
|
4114
4227
|
// src/commands/volume/ls.ts
|
|
4115
|
-
import { Command as
|
|
4116
|
-
var
|
|
4228
|
+
import { Command as Command61 } from "commander";
|
|
4229
|
+
var lsCommand7 = new Command61("ls").alias("list").description("list volumes: size, what they occupy, which box has them").option("-a, --all", "every volume on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
4117
4230
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4118
4231
|
try {
|
|
4119
4232
|
const cloud = client.target.kind === "cloud";
|
|
@@ -4144,8 +4257,8 @@ var lsCommand6 = new Command57("ls").alias("list").description("list volumes: si
|
|
|
4144
4257
|
});
|
|
4145
4258
|
|
|
4146
4259
|
// src/commands/volume/rm.ts
|
|
4147
|
-
import { Command as
|
|
4148
|
-
var
|
|
4260
|
+
import { Command as Command62 } from "commander";
|
|
4261
|
+
var rmCommand7 = new Command62("rm").alias("remove").description("delete a volume and everything on it (detach it first)").argument("<name>", "volume name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
|
|
4149
4262
|
if (!await confirm(`Delete volume ${name} and everything on it?`, opts.yes ?? false)) {
|
|
4150
4263
|
info("cancelled");
|
|
4151
4264
|
process.exitCode = 1;
|
|
@@ -4161,17 +4274,17 @@ var rmCommand6 = new Command58("rm").alias("remove").description("delete a volum
|
|
|
4161
4274
|
});
|
|
4162
4275
|
|
|
4163
4276
|
// src/commands/volume/index.ts
|
|
4164
|
-
var volumeCommand = new
|
|
4277
|
+
var volumeCommand = new Command63("volume").aliases(["volumes", "vol"]).description("disks of their own: create one, attach it to a box at /mnt/<name>, move it to another box later").addCommand(createCommand2).addCommand(lsCommand7).addCommand(attachCommand).addCommand(detachCommand).addCommand(rmCommand7);
|
|
4165
4278
|
for (const cmd of volumeCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal volumes)");
|
|
4166
4279
|
|
|
4167
4280
|
// src/commands/env/index.ts
|
|
4168
|
-
import { Command as
|
|
4281
|
+
import { Command as Command67 } from "commander";
|
|
4169
4282
|
|
|
4170
4283
|
// src/commands/env/ls.ts
|
|
4171
|
-
import { Command as
|
|
4284
|
+
import { Command as Command64 } from "commander";
|
|
4172
4285
|
|
|
4173
4286
|
// src/commands/env/shared.ts
|
|
4174
|
-
function
|
|
4287
|
+
function requireCloud3(client) {
|
|
4175
4288
|
if (client.target.kind === "local") throw new KvboxError("kvbox env needs kvbox.sh: kvbox login first");
|
|
4176
4289
|
return client.target.org ?? client.target.user ?? "you";
|
|
4177
4290
|
}
|
|
@@ -4195,7 +4308,7 @@ function firstBootHint(box, name) {
|
|
|
4195
4308
|
}
|
|
4196
4309
|
|
|
4197
4310
|
// src/commands/env/ls.ts
|
|
4198
|
-
var
|
|
4311
|
+
var lsCommand8 = new Command64("ls").alias("list").description("list the variables (a secret shows as (sealed))").option("--box <box>", "what this box gets: its own variables and the ones it inherits").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
4199
4312
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
4200
4313
|
try {
|
|
4201
4314
|
if (opts.box !== void 0) {
|
|
@@ -4217,7 +4330,7 @@ var lsCommand7 = new Command60("ls").alias("list").description("list the variabl
|
|
|
4217
4330
|
table([...own.vars.map((v) => row(v, "box")), ...inherited.map((v) => row(v, color.dim(slug)))]);
|
|
4218
4331
|
return;
|
|
4219
4332
|
}
|
|
4220
|
-
const owner =
|
|
4333
|
+
const owner = requireCloud3(client);
|
|
4221
4334
|
const vars = await client.listEnv();
|
|
4222
4335
|
if (opts.json) {
|
|
4223
4336
|
json(vars);
|
|
@@ -4234,12 +4347,12 @@ var lsCommand7 = new Command60("ls").alias("list").description("list the variabl
|
|
|
4234
4347
|
});
|
|
4235
4348
|
|
|
4236
4349
|
// src/commands/env/rm.ts
|
|
4237
|
-
import { Command as
|
|
4238
|
-
var
|
|
4350
|
+
import { Command as Command65 } from "commander";
|
|
4351
|
+
var rmCommand8 = new Command65("rm").alias("remove").description("remove variables; boxes lose them when they next start").argument("<names...>", "variable names").option("-y, --yes", "do not ask for confirmation").option("--box <box>", "remove this box's own variables (yours, or the org's, of the same name come back)").option("--json", "print as JSON").action(async (names, opts, cmd) => {
|
|
4239
4352
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
4240
4353
|
try {
|
|
4241
4354
|
const target = opts.box === void 0 ? void 0 : await findBox2(client, opts.box);
|
|
4242
|
-
const owner = target === void 0 ?
|
|
4355
|
+
const owner = target === void 0 ? requireCloud3(client) : `box ${target.ref}`;
|
|
4243
4356
|
if (!await confirm(`Remove ${names.join(", ")} from ${owner}'s variables?`, opts.yes ?? false)) {
|
|
4244
4357
|
info("cancelled");
|
|
4245
4358
|
process.exitCode = 1;
|
|
@@ -4272,11 +4385,11 @@ var rmCommand7 = new Command61("rm").alias("remove").description("remove variabl
|
|
|
4272
4385
|
});
|
|
4273
4386
|
|
|
4274
4387
|
// src/commands/env/set.ts
|
|
4275
|
-
import { Command as
|
|
4276
|
-
var setCommand2 = new
|
|
4388
|
+
import { Command as Command66 } from "commander";
|
|
4389
|
+
var setCommand2 = new Command66("set").description("add or change a variable; boxes get it when they next start").argument("[name]", "variable name, e.g. DATABASE_URL (asked for when left out)").argument("[value]", "its value (asked for when left out; hidden with --secret)").option("--secret", "write-only: the value is never shown again, by any command").option("--box <box>", "this box's own variable, over yours (or the org's) of the same name").option("--json", "print as JSON").action(async (nameArg, valueArg, opts, cmd) => {
|
|
4277
4390
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
4278
4391
|
try {
|
|
4279
|
-
const owner = opts.box === void 0 ?
|
|
4392
|
+
const owner = opts.box === void 0 ? requireCloud3(client) : void 0;
|
|
4280
4393
|
const target = opts.box === void 0 ? void 0 : await findBox2(client, opts.box);
|
|
4281
4394
|
const ask = interactive();
|
|
4282
4395
|
if ((nameArg === void 0 || valueArg === void 0) && !ask) throw new KvboxError("give the name and the value: kvbox env set NAME VALUE (or run it in a terminal to be asked)");
|
|
@@ -4310,17 +4423,17 @@ var setCommand2 = new Command62("set").description("add or change a variable; bo
|
|
|
4310
4423
|
});
|
|
4311
4424
|
|
|
4312
4425
|
// src/commands/env/index.ts
|
|
4313
|
-
var envCommand = new
|
|
4426
|
+
var envCommand = new Command67("env").description("environment variables every box of yours gets when it starts (secrets too)").addCommand(lsCommand8, { isDefault: true }).addCommand(setCommand2).addCommand(rmCommand8);
|
|
4314
4427
|
for (const cmd of envCommand.commands) cmd.option("--org <slug>", "the org's variables instead of yours");
|
|
4315
4428
|
|
|
4316
4429
|
// src/commands/domain/index.ts
|
|
4317
|
-
import { Command as
|
|
4430
|
+
import { Command as Command71 } from "commander";
|
|
4318
4431
|
|
|
4319
4432
|
// src/commands/domain/add.ts
|
|
4320
|
-
import { Command as
|
|
4433
|
+
import { Command as Command68 } from "commander";
|
|
4321
4434
|
|
|
4322
4435
|
// src/commands/domain/shared.ts
|
|
4323
|
-
function
|
|
4436
|
+
function requireCloud4(client) {
|
|
4324
4437
|
if (client.target.kind !== "cloud") throw new KvboxError("custom domains need the kvbox cloud: kvbox login (this host's own socket has none)");
|
|
4325
4438
|
}
|
|
4326
4439
|
var boxOf2 = (d, user) => user !== void 0 && d.owner !== user ? `${d.owner}/${d.box}` : d.box;
|
|
@@ -4337,12 +4450,12 @@ function hostIn(name, zone) {
|
|
|
4337
4450
|
}
|
|
4338
4451
|
|
|
4339
4452
|
// src/commands/domain/add.ts
|
|
4340
|
-
var addCommand3 = new
|
|
4453
|
+
var addCommand3 = new Command68("add").description("serve a box at a domain of your own, https://<domain>, with its certificate made for you").argument("<domain>", "a domain you control, like example.com or app.example.com").argument("<box>", "box name").option("--port <port>", "the box port the domain serves (default: the port of its kvbox.app address)").option("--json", "print the domain as JSON").action(async (domainArg, name, opts, cmd) => {
|
|
4341
4454
|
const domain = assertDomain(domainArg.trim().toLowerCase());
|
|
4342
4455
|
const port = opts.port === void 0 ? void 0 : parsePorts([opts.port])[0];
|
|
4343
4456
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4344
4457
|
try {
|
|
4345
|
-
|
|
4458
|
+
requireCloud4(client);
|
|
4346
4459
|
const user = me(client);
|
|
4347
4460
|
const box = displayName(await findBox(client, name), user);
|
|
4348
4461
|
const d = await spin(`adding ${domain}\u2026`, client.addDomain(box, { domain, ...port !== void 0 ? { port } : {} }));
|
|
@@ -4373,11 +4486,11 @@ kvbox checks every minute; ${domain} is served at ${d.url} once its records are
|
|
|
4373
4486
|
});
|
|
4374
4487
|
|
|
4375
4488
|
// src/commands/domain/ls.ts
|
|
4376
|
-
import { Command as
|
|
4377
|
-
var
|
|
4489
|
+
import { Command as Command69 } from "commander";
|
|
4490
|
+
var lsCommand9 = new Command69("ls").alias("list").description("list your custom domains and whether they are live").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
4378
4491
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4379
4492
|
try {
|
|
4380
|
-
|
|
4493
|
+
requireCloud4(client);
|
|
4381
4494
|
const user = me(client);
|
|
4382
4495
|
const domains = await client.listDomains();
|
|
4383
4496
|
if (opts.json) {
|
|
@@ -4403,12 +4516,12 @@ var lsCommand8 = new Command65("ls").alias("list").description("list your custom
|
|
|
4403
4516
|
});
|
|
4404
4517
|
|
|
4405
4518
|
// src/commands/domain/rm.ts
|
|
4406
|
-
import { Command as
|
|
4407
|
-
var
|
|
4519
|
+
import { Command as Command70 } from "commander";
|
|
4520
|
+
var rmCommand9 = new Command70("rm").alias("remove").description("stop serving a box at a custom domain").argument("<domain>", "the domain").option("-y, --yes", "do not ask for confirmation").action(async (domainArg, opts, cmd) => {
|
|
4408
4521
|
const domain = domainArg.trim().toLowerCase();
|
|
4409
4522
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4410
4523
|
try {
|
|
4411
|
-
|
|
4524
|
+
requireCloud4(client);
|
|
4412
4525
|
const found = (await client.listDomains()).find((d) => d.domain === domain);
|
|
4413
4526
|
if (!found) throw new KvboxError(`domain ${domain}: not found (kvbox domain ls)`);
|
|
4414
4527
|
const box = boxOf2(found, me(client));
|
|
@@ -4425,12 +4538,12 @@ var rmCommand8 = new Command66("rm").alias("remove").description("stop serving a
|
|
|
4425
4538
|
});
|
|
4426
4539
|
|
|
4427
4540
|
// src/commands/domain/index.ts
|
|
4428
|
-
var domainCommand = new
|
|
4541
|
+
var domainCommand = new Command71("domain").alias("domains").description("serve a box at a domain of your own").addCommand(addCommand3).addCommand(lsCommand9).addCommand(rmCommand9);
|
|
4429
4542
|
for (const cmd of domainCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
4430
4543
|
|
|
4431
4544
|
// src/program.ts
|
|
4432
4545
|
function buildProgram() {
|
|
4433
|
-
const program = new
|
|
4546
|
+
const program = new Command72("kvbox").description("self-hosted Firecracker microVMs with Docker-like ergonomics").version(VERSION, "-v, --version").option("--local", "use this machine's kvbox-server over its socket, ignoring kvbox login").option("--org <slug>", "the org: where kvbox new creates, and which box a name means when it is not one of yours; before the command here, or after it").showHelpAfterError().enablePositionalOptions();
|
|
4434
4547
|
program.addCommand(vmCommand);
|
|
4435
4548
|
program.addCommand(snapshotsCommand);
|
|
4436
4549
|
program.addCommand(volumeCommand);
|