@kvbox/cli 0.5.11 → 0.5.12
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 +38 -27
- package/dist/kvbox.js.map +1 -1
- package/package.json +1 -1
package/dist/kvbox.js
CHANGED
|
@@ -162,7 +162,7 @@ function versionOf(srcFileUrl, injected) {
|
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
// src/version.ts
|
|
165
|
-
var VERSION = versionOf(import.meta.url, true ? "0.5.
|
|
165
|
+
var VERSION = versionOf(import.meta.url, true ? "0.5.12" : void 0);
|
|
166
166
|
|
|
167
167
|
// src/commands/vm/index.ts
|
|
168
168
|
import { Command as Command17 } from "commander";
|
|
@@ -820,6 +820,7 @@ async function resolveTarget(opts, p = paths()) {
|
|
|
820
820
|
}
|
|
821
821
|
return { kind: "local", socketPath: p.serverSock };
|
|
822
822
|
}
|
|
823
|
+
var allQuery = (opts) => opts.all ? "?all=1" : "";
|
|
823
824
|
var ServerClient = class {
|
|
824
825
|
constructor(target, opts = {}) {
|
|
825
826
|
this.target = target;
|
|
@@ -886,9 +887,12 @@ var ServerClient = class {
|
|
|
886
887
|
capacity() {
|
|
887
888
|
return this.call("GET", "/capacity", CapacitySchema);
|
|
888
889
|
}
|
|
889
|
-
/**
|
|
890
|
-
|
|
891
|
-
|
|
890
|
+
/**
|
|
891
|
+
* Through a control plane: the user's boxes and their orgs', the `--org` org's, or `org`'s;
|
|
892
|
+
* `all`: every box on the platform (platform admins only, #78).
|
|
893
|
+
*/
|
|
894
|
+
listMachines(opts = {}) {
|
|
895
|
+
return this.call("GET", `/machines${allQuery(opts)}`, z3.array(MachineSchema), void 0, opts.org);
|
|
892
896
|
}
|
|
893
897
|
createMachine(req) {
|
|
894
898
|
return this.call("POST", "/machines", MachineSchema, req);
|
|
@@ -930,8 +934,9 @@ var ServerClient = class {
|
|
|
930
934
|
return this.call("GET", `/machines/${encodeURIComponent(name)}/usage${query}`, MachineUsageSchema);
|
|
931
935
|
}
|
|
932
936
|
/** Every box of the caller over the window (#41 on a host, #42 through a control plane); dates as the user wrote them. */
|
|
933
|
-
usageReport(since, until) {
|
|
937
|
+
usageReport(since, until, all = false) {
|
|
934
938
|
const q = new URLSearchParams();
|
|
939
|
+
if (all) q.set("all", "1");
|
|
935
940
|
if (since !== void 0) q.set("since", since);
|
|
936
941
|
if (until !== void 0) q.set("until", until);
|
|
937
942
|
const query = q.size === 0 ? "" : `?${q.toString()}`;
|
|
@@ -944,8 +949,9 @@ var ServerClient = class {
|
|
|
944
949
|
deleteMachine(name) {
|
|
945
950
|
return this.call("DELETE", `/machines/${encodeURIComponent(name)}`, z3.undefined());
|
|
946
951
|
}
|
|
947
|
-
|
|
948
|
-
|
|
952
|
+
/** Like `listMachines`, for snapshots. */
|
|
953
|
+
listSnapshots(opts = {}) {
|
|
954
|
+
return this.call("GET", `/snapshots${allQuery(opts)}`, z3.array(SnapshotSchema), void 0, opts.org);
|
|
949
955
|
}
|
|
950
956
|
createSnapshot(req) {
|
|
951
957
|
return this.call("POST", "/snapshots", SnapshotSchema, req);
|
|
@@ -1031,6 +1037,11 @@ async function wakeUp(client, box, name) {
|
|
|
1031
1037
|
return box;
|
|
1032
1038
|
}
|
|
1033
1039
|
}
|
|
1040
|
+
function boxesFor(client, text) {
|
|
1041
|
+
const slash = text.indexOf("/");
|
|
1042
|
+
if (slash === -1 || client.target.kind !== "cloud") return client.listMachines();
|
|
1043
|
+
return client.listMachines({ org: text.slice(0, slash).split("@")[0] });
|
|
1044
|
+
}
|
|
1034
1045
|
var me = (client) => client.target.kind === "cloud" ? client.target.user : void 0;
|
|
1035
1046
|
async function clientFor(opts, client = {}) {
|
|
1036
1047
|
return new ServerClient(await resolveTarget(opts), client);
|
|
@@ -1200,7 +1211,7 @@ var connectCommand = new Command2("connect").alias("cn").description("open a she
|
|
|
1200
1211
|
let cert;
|
|
1201
1212
|
let owner;
|
|
1202
1213
|
try {
|
|
1203
|
-
let box = pickRef(await client
|
|
1214
|
+
let box = pickRef(await boxesFor(client, name), name, me(client));
|
|
1204
1215
|
if (!box) throw new KvboxError(`box ${name}: not found (kvbox ls)`);
|
|
1205
1216
|
cert = await ensureCert(client, void 0, void 0, { owner: box.owner });
|
|
1206
1217
|
owner = box.owner;
|
|
@@ -1278,7 +1289,7 @@ var execCommand = new Command3("exec").description("run a command in a box and e
|
|
|
1278
1289
|
let cert;
|
|
1279
1290
|
let owner;
|
|
1280
1291
|
try {
|
|
1281
|
-
let box = pickRef(await client
|
|
1292
|
+
let box = pickRef(await boxesFor(client, name), name, me(client));
|
|
1282
1293
|
if (!box) throw new KvboxError(`box ${name}: not found (kvbox ls)`);
|
|
1283
1294
|
if (box.status === "stopped") throw new KvboxError(`box ${name} is stopped (kvbox start ${name})`);
|
|
1284
1295
|
cert = await ensureCert(client, void 0, void 0, { owner: box.owner });
|
|
@@ -1334,7 +1345,7 @@ var hibernateCommand = new Command4("hibernate").description("save a box's memor
|
|
|
1334
1345
|
});
|
|
1335
1346
|
|
|
1336
1347
|
// src/commands/vm/ls.ts
|
|
1337
|
-
import { Command as Command5
|
|
1348
|
+
import { Command as Command5 } from "commander";
|
|
1338
1349
|
function ownerCell(b, me2) {
|
|
1339
1350
|
const slug = slugOf(b.owner);
|
|
1340
1351
|
if (slug === me2) return "private";
|
|
@@ -1344,10 +1355,10 @@ function addressOf(b) {
|
|
|
1344
1355
|
if (b.ssh !== void 0) return `${b.ssh.host}:${b.ssh.port}`;
|
|
1345
1356
|
return b.ip === "" ? "-" : b.ip;
|
|
1346
1357
|
}
|
|
1347
|
-
var lsCommand = new Command5("ls").description("list boxes with status and address (yours and your orgs'; --org <slug> for one org)").
|
|
1358
|
+
var lsCommand = new Command5("ls").description("list boxes with status and address (yours and your orgs'; --org <slug> for one org)").option("-a, --all", "every box on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
1348
1359
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
1349
1360
|
try {
|
|
1350
|
-
const boxes = await client.listMachines();
|
|
1361
|
+
const boxes = await client.listMachines({ all: opts.all });
|
|
1351
1362
|
if (opts.json) {
|
|
1352
1363
|
json(boxes);
|
|
1353
1364
|
return;
|
|
@@ -1388,8 +1399,8 @@ var pauseCommand = new Command6("pause").description("freeze a box in place (mem
|
|
|
1388
1399
|
});
|
|
1389
1400
|
|
|
1390
1401
|
// src/commands/vm/rescale.ts
|
|
1391
|
-
import { Command as Command7, Option as
|
|
1392
|
-
var rescaleCommand = new Command7("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
|
|
1402
|
+
import { Command as Command7, Option as Option2 } from "commander";
|
|
1403
|
+
var rescaleCommand = new Command7("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 Option2("-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) => {
|
|
1393
1404
|
const req = {
|
|
1394
1405
|
...opts.size !== void 0 ? { size: opts.size } : {},
|
|
1395
1406
|
...opts.vcpu !== void 0 ? { vcpu: parseCount(opts.vcpu) } : {},
|
|
@@ -1399,7 +1410,7 @@ var rescaleCommand = new Command7("rescale").description("change a box's vCPUs,
|
|
|
1399
1410
|
if (Object.keys(req).length === 0) throw new KvboxError("nothing to change: give --size, --vcpu, --mem or --disk");
|
|
1400
1411
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
1401
1412
|
try {
|
|
1402
|
-
const before = pickRef(await client
|
|
1413
|
+
const before = pickRef(await boxesFor(client, name), name, me(client));
|
|
1403
1414
|
if (!before) throw new KvboxError(`box ${name}: not found (kvbox ls)`);
|
|
1404
1415
|
const box = await spin(`rescaling ${name}\u2026`, client.rescaleMachine(displayName(before, me(client)), req));
|
|
1405
1416
|
if (opts.json) {
|
|
@@ -1451,7 +1462,7 @@ import { Command as Command9 } from "commander";
|
|
|
1451
1462
|
var rmCommand = new Command9("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) => {
|
|
1452
1463
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
1453
1464
|
try {
|
|
1454
|
-
const box = pickRef(await client
|
|
1465
|
+
const box = pickRef(await boxesFor(client, name), name, me(client));
|
|
1455
1466
|
if (!box) throw new KvboxError(`box ${name}: not found (kvbox ls)`);
|
|
1456
1467
|
const ref = displayName(box, me(client));
|
|
1457
1468
|
if (!await confirm(`Destroy box ${ref} and its disk?`, opts.yes ?? false)) {
|
|
@@ -1473,7 +1484,7 @@ var setCommand = new Command10("set").description("change a box's settings, e.g.
|
|
|
1473
1484
|
const autoHibernateSec = parseIdleTimeout(opts.autoHibernate);
|
|
1474
1485
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
1475
1486
|
try {
|
|
1476
|
-
const found = pickRef(await client
|
|
1487
|
+
const found = pickRef(await boxesFor(client, name), name, me(client));
|
|
1477
1488
|
if (!found) throw new KvboxError(`box ${name}: not found (kvbox ls)`);
|
|
1478
1489
|
const box = await spin(`updating ${name}\u2026`, client.setMachine(displayName(found, me(client)), { autoHibernateSec }));
|
|
1479
1490
|
if (opts.json) {
|
|
@@ -1514,10 +1525,10 @@ var stopCommand = new Command12("stop").description("shut a box down (its disk i
|
|
|
1514
1525
|
|
|
1515
1526
|
// src/commands/vm/top.ts
|
|
1516
1527
|
import { Command as Command13 } from "commander";
|
|
1517
|
-
var topCommand = new Command13("top").description("load, memory and disk of each running box, as the box itself sees them").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
1528
|
+
var topCommand = new Command13("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) => {
|
|
1518
1529
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
1519
1530
|
try {
|
|
1520
|
-
const running = (await client.listMachines()).filter((b) => b.status === "running");
|
|
1531
|
+
const running = (await client.listMachines({ all: opts.all })).filter((b) => b.status === "running");
|
|
1521
1532
|
const entries = await mapLimit(running, ASK_AT_ONCE, async (b) => {
|
|
1522
1533
|
const who = { name: b.name, owner: b.owner, ...b.ownerKind === void 0 ? {} : { ownerKind: b.ownerKind } };
|
|
1523
1534
|
try {
|
|
@@ -1578,7 +1589,7 @@ import { Command as Command14 } from "commander";
|
|
|
1578
1589
|
var updateCommand = new Command14("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) => {
|
|
1579
1590
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
1580
1591
|
try {
|
|
1581
|
-
const before = pickRef(await client
|
|
1592
|
+
const before = pickRef(await boxesFor(client, name), name, me(client));
|
|
1582
1593
|
if (!before) throw new KvboxError(`box ${name}: not found (kvbox ls)`);
|
|
1583
1594
|
const box = await spin(`updating ${name}\u2026`, client.updateMachine(displayName(before, me(client))));
|
|
1584
1595
|
if (opts.json) {
|
|
@@ -2009,12 +2020,12 @@ function describeSession(session) {
|
|
|
2009
2020
|
import { Command as Command32 } from "commander";
|
|
2010
2021
|
|
|
2011
2022
|
// src/commands/snapshots/ls.ts
|
|
2012
|
-
import { Command as Command29
|
|
2013
|
-
var lsCommand2 = new Command29("ls").description("list snapshots (yours and your orgs'; --org <slug> for one org)").
|
|
2023
|
+
import { Command as Command29 } from "commander";
|
|
2024
|
+
var lsCommand2 = new Command29("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) => {
|
|
2014
2025
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
2015
2026
|
try {
|
|
2016
2027
|
const cloud = client.target.kind === "cloud";
|
|
2017
|
-
const snaps = await client.listSnapshots();
|
|
2028
|
+
const snaps = await client.listSnapshots({ all: opts.all });
|
|
2018
2029
|
if (opts.json) {
|
|
2019
2030
|
json(snaps);
|
|
2020
2031
|
return;
|
|
@@ -2120,7 +2131,7 @@ function orgRows(orgs) {
|
|
|
2120
2131
|
}
|
|
2121
2132
|
|
|
2122
2133
|
// src/commands/org/members.ts
|
|
2123
|
-
import { Command as Command34, Option as
|
|
2134
|
+
import { Command as Command34, Option as Option3 } from "commander";
|
|
2124
2135
|
var lsCommand4 = new Command34("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) => {
|
|
2125
2136
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
2126
2137
|
try {
|
|
@@ -2135,7 +2146,7 @@ var lsCommand4 = new Command34("ls").description("list an org's members and thei
|
|
|
2135
2146
|
await client.close();
|
|
2136
2147
|
}
|
|
2137
2148
|
});
|
|
2138
|
-
var addCommand = new Command34("add").description("add a user to an org (admins and owners; only an owner can add an owner)").argument("<user>", "their username").addOption(new
|
|
2149
|
+
var addCommand = new Command34("add").description("add a user to an org (admins and owners; only an owner can add an owner)").argument("<user>", "their username").addOption(new Option3("-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) => {
|
|
2139
2150
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
2140
2151
|
try {
|
|
2141
2152
|
const slug = orgFor(opts, client.target);
|
|
@@ -2215,7 +2226,7 @@ var orgCommand = new Command38("org").description("orgs: shared slugs that own b
|
|
|
2215
2226
|
|
|
2216
2227
|
// src/commands/usage.ts
|
|
2217
2228
|
import { Command as Command39 } from "commander";
|
|
2218
|
-
var usageCommand2 = new Command39("usage").description("what your boxes 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("--json", "print as JSON").action(async (opts, cmd) => {
|
|
2229
|
+
var usageCommand2 = new Command39("usage").description("what your boxes 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("--json", "print as JSON").action(async (opts, cmd) => {
|
|
2219
2230
|
for (const [name, value] of [
|
|
2220
2231
|
["since", opts.since],
|
|
2221
2232
|
["until", opts.until]
|
|
@@ -2225,7 +2236,7 @@ var usageCommand2 = new Command39("usage").description("what your boxes used thi
|
|
|
2225
2236
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
2226
2237
|
try {
|
|
2227
2238
|
if (client.target.kind === "local" && cmd.optsWithGlobals().org) throw new KvboxError("--org needs a control plane: kvbox login, or drop --org");
|
|
2228
|
-
const report = await client.usageReport(opts.since, opts.until);
|
|
2239
|
+
const report = await client.usageReport(opts.since, opts.until, opts.all);
|
|
2229
2240
|
if (opts.json) {
|
|
2230
2241
|
json(report);
|
|
2231
2242
|
return;
|