@kvbox/cli 0.5.44 → 0.5.46
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 +274 -68
- package/dist/kvbox.js.map +1 -1
- package/package.json +1 -1
package/dist/kvbox.js
CHANGED
|
@@ -29,10 +29,10 @@ var width = (s) => s.replace(ANSI, "").length;
|
|
|
29
29
|
function table(rows2, columns) {
|
|
30
30
|
if (rows2.length === 0) return;
|
|
31
31
|
const cols = columns ?? Object.keys(rows2[0]);
|
|
32
|
-
const cells = rows2.map((r) => cols.map((
|
|
33
|
-
const widths = cols.map((
|
|
32
|
+
const cells = rows2.map((r) => cols.map((c2) => String(r[c2] ?? "")));
|
|
33
|
+
const widths = cols.map((c2, i) => Math.max(c2.length, ...cells.map((r) => width(r[i]))));
|
|
34
34
|
const line = (parts) => parts.map((p, i) => p + " ".repeat(Math.max(0, widths[i] - width(p)))).join(" ").trimEnd();
|
|
35
|
-
process.stdout.write(color.dim(line(cols.map((
|
|
35
|
+
process.stdout.write(color.dim(line(cols.map((c2) => c2.toUpperCase()))) + "\n");
|
|
36
36
|
for (const row of cells) process.stdout.write(line(row) + "\n");
|
|
37
37
|
}
|
|
38
38
|
function info(msg) {
|
|
@@ -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 Command70 } from "commander";
|
|
153
153
|
|
|
154
154
|
// ../shared/src/version.ts
|
|
155
155
|
import { createRequire } from "module";
|
|
@@ -164,7 +164,7 @@ 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.46" : void 0);
|
|
168
168
|
|
|
169
169
|
// src/commands/vm/index.ts
|
|
170
170
|
import { Command as Command37 } from "commander";
|
|
@@ -191,6 +191,14 @@ function paths(home = kvboxHome()) {
|
|
|
191
191
|
serverSock: join(home, "server.sock"),
|
|
192
192
|
serverPid: join(home, "server.pid"),
|
|
193
193
|
serverLog: join(home, "server.log"),
|
|
194
|
+
/**
|
|
195
|
+
* The host's self-update (`POST /update`, the control plane's admin): `update.json` is its state
|
|
196
|
+
* (install-server.sh --update writes it), `update/` holds the downloaded script and its log.
|
|
197
|
+
*/
|
|
198
|
+
updateState: join(home, "update.json"),
|
|
199
|
+
updateDir: join(home, "update"),
|
|
200
|
+
updateScript: join(home, "update", "install-server.sh"),
|
|
201
|
+
updateLog: join(home, "update", "update.log"),
|
|
194
202
|
/** The CLI's login to the control plane (`kvbox login`): url, bearer token, user. Mode 600. */
|
|
195
203
|
cli: join(home, "cli.json"),
|
|
196
204
|
/** The CLI's last look at npm for a newer @kvbox/cli: `{checkedAt, latest}`, at most once a day (cli update.ts). */
|
|
@@ -693,6 +701,11 @@ var CreateMachineRequest = z2.object({
|
|
|
693
701
|
* `@kvbox/shared/country`. Only the control plane reads it.
|
|
694
702
|
*/
|
|
695
703
|
country: z2.string().optional(),
|
|
704
|
+
/**
|
|
705
|
+
* Place the box on the host of this name and nowhere else (`kvbox new --host kvbox2`, a hidden flag):
|
|
706
|
+
* an admin's, to try a host out. Only the control plane reads it, and refuses it from anyone else.
|
|
707
|
+
*/
|
|
708
|
+
host: z2.string().optional(),
|
|
696
709
|
/** The image to boot (#87, `kvbox new --base postgres`). Absent: the base image. */
|
|
697
710
|
image: z2.string().optional(),
|
|
698
711
|
/** The box's own environment variables (#87, `kvbox new -e NAME=value`), over its owner's. */
|
|
@@ -772,7 +785,9 @@ var CapacitySchema = z2.object({
|
|
|
772
785
|
* The images a new box can be made from here (#87), with the version `new` uses; the base is `base`.
|
|
773
786
|
* Absent on a host from before images: it has only the base.
|
|
774
787
|
*/
|
|
775
|
-
images: z2.array(z2.object({ name: z2.string(), version: z2.string() })).optional()
|
|
788
|
+
images: z2.array(z2.object({ name: z2.string(), version: z2.string() })).optional(),
|
|
789
|
+
/** kvbox-server's version, so the control plane's host list shows it without a call per host. Older servers omit it. */
|
|
790
|
+
version: z2.string().optional()
|
|
776
791
|
});
|
|
777
792
|
var ImageSchema = z2.object({ name: z2.string(), version: z2.string().nullable() });
|
|
778
793
|
var RecoveryReportSchema = z2.object({
|
|
@@ -781,6 +796,16 @@ var RecoveryReportSchema = z2.object({
|
|
|
781
796
|
leftStopped: z2.array(z2.string()),
|
|
782
797
|
failed: z2.array(z2.object({ box: z2.string(), error: z2.string() }))
|
|
783
798
|
});
|
|
799
|
+
var HostUpdateSchema = z2.object({
|
|
800
|
+
state: z2.enum(["running", "done", "failed"]),
|
|
801
|
+
startedAt: z2.string(),
|
|
802
|
+
finishedAt: z2.string().nullable(),
|
|
803
|
+
/** kvbox-server's version when the update started, and when it ended (null while running or when it failed before). */
|
|
804
|
+
from: z2.string(),
|
|
805
|
+
to: z2.string().nullable(),
|
|
806
|
+
error: z2.string().nullable(),
|
|
807
|
+
needsManual: z2.array(z2.string())
|
|
808
|
+
});
|
|
784
809
|
var HealthSchema = z2.object({
|
|
785
810
|
ok: z2.literal(true),
|
|
786
811
|
version: z2.string(),
|
|
@@ -809,7 +834,9 @@ var HealthSchema = z2.object({
|
|
|
809
834
|
lastRestartAt: z2.string().nullable().optional()
|
|
810
835
|
}).nullable().optional(),
|
|
811
836
|
/** Boxes brought back at the server's last start; null when there were none or it is still at it. Older servers omit it. */
|
|
812
|
-
recovery: RecoveryReportSchema.nullable().optional()
|
|
837
|
+
recovery: RecoveryReportSchema.nullable().optional(),
|
|
838
|
+
/** The last self-update; null when none ran. Older servers omit it. */
|
|
839
|
+
update: HostUpdateSchema.nullable().optional()
|
|
813
840
|
});
|
|
814
841
|
var MachineUsageSchema = z2.object({
|
|
815
842
|
name: z2.string(),
|
|
@@ -945,7 +972,9 @@ var CloudUserSchema = z2.object({
|
|
|
945
972
|
* gates nobody, hence the defaults: a newer CLI must still parse its answers.
|
|
946
973
|
*/
|
|
947
974
|
active: z2.boolean().default(true),
|
|
948
|
-
activatedBy: ActivatedBySchema.nullable().default(null)
|
|
975
|
+
activatedBy: ActivatedBySchema.nullable().default(null),
|
|
976
|
+
/** When too many wrong passwords locked the account (#161); null when it is not locked. Older control planes omit it. */
|
|
977
|
+
lockedAt: z2.string().nullable().default(null)
|
|
949
978
|
});
|
|
950
979
|
var ORG_ROLES = ["owner", "admin", "member"];
|
|
951
980
|
var OrgRoleSchema = z2.enum(ORG_ROLES);
|
|
@@ -983,10 +1012,14 @@ var BalanceSchema = z2.object({
|
|
|
983
1012
|
currency: z2.string(),
|
|
984
1013
|
topUps: z2.number(),
|
|
985
1014
|
spent: z2.number(),
|
|
986
|
-
/** The first moment usage counts from: the slug's first top-up; null when it has none. */
|
|
1015
|
+
/** The first moment usage counts from: the slug's first top-up or redeemed code; null when it has none. */
|
|
987
1016
|
since: z2.string().nullable(),
|
|
988
1017
|
/** When the slug ran out and its boxes were hibernated (the `sweep-credit` job); null in good standing. Absent from a control plane older than this field. */
|
|
989
|
-
suspendedAt: z2.string().nullable().default(null)
|
|
1018
|
+
suspendedAt: z2.string().nullable().default(null),
|
|
1019
|
+
/** Promo credit left (#163), already counted in `balance`; 0 with none. Absent from a control plane older than this field. */
|
|
1020
|
+
promo: z2.number().default(0),
|
|
1021
|
+
/** When the next promo credit expires; null with none left. */
|
|
1022
|
+
promoExpiresAt: z2.string().nullable().default(null)
|
|
990
1023
|
});
|
|
991
1024
|
var TopUpRequestSchema = z2.object({
|
|
992
1025
|
slug: z2.string().min(1),
|
|
@@ -1004,6 +1037,41 @@ var TopUpSchema = z2.object({
|
|
|
1004
1037
|
note: z2.string().nullable(),
|
|
1005
1038
|
at: z2.string()
|
|
1006
1039
|
});
|
|
1040
|
+
var CreateCodeRequestSchema = z2.object({
|
|
1041
|
+
/** In the control plane's currency, cents at most. */
|
|
1042
|
+
amount: z2.number().positive().multipleOf(0.01, "amount is in cents at most"),
|
|
1043
|
+
/** A day (`2026-12-11`, through the end of it, UTC) or an ISO time. The credit is gone then, and so is the code. */
|
|
1044
|
+
expiresAt: z2.string().min(1),
|
|
1045
|
+
note: z2.string().max(200).optional()
|
|
1046
|
+
});
|
|
1047
|
+
var CreditCodeSchema = z2.object({
|
|
1048
|
+
code: z2.string(),
|
|
1049
|
+
amount: z2.number(),
|
|
1050
|
+
currency: z2.string(),
|
|
1051
|
+
expiresAt: z2.string(),
|
|
1052
|
+
note: z2.string().nullable(),
|
|
1053
|
+
status: z2.enum(["unused", "redeemed", "expired", "revoked"]),
|
|
1054
|
+
createdBy: z2.string(),
|
|
1055
|
+
createdAt: z2.string(),
|
|
1056
|
+
/** Who redeemed it and the slug the credit went to (their own, or an org they own). */
|
|
1057
|
+
redeemedBy: z2.string().nullable(),
|
|
1058
|
+
redeemedSlug: z2.string().nullable(),
|
|
1059
|
+
redeemedAt: z2.string().nullable(),
|
|
1060
|
+
revokedAt: z2.string().nullable()
|
|
1061
|
+
});
|
|
1062
|
+
var RedeemRequestSchema = z2.object({
|
|
1063
|
+
code: z2.string().min(1).max(64),
|
|
1064
|
+
org: z2.string().min(1).optional()
|
|
1065
|
+
});
|
|
1066
|
+
var RedeemResponseSchema = z2.object({
|
|
1067
|
+
slug: z2.string(),
|
|
1068
|
+
amount: z2.number(),
|
|
1069
|
+
currency: z2.string(),
|
|
1070
|
+
expiresAt: z2.string(),
|
|
1071
|
+
balance: BalanceSchema,
|
|
1072
|
+
/** The slug was out of credit and this put it back above zero: it may start boxes again. */
|
|
1073
|
+
reinstated: z2.boolean()
|
|
1074
|
+
});
|
|
1007
1075
|
var TOP_UP_AMOUNTS = [10, 25, 50, 100];
|
|
1008
1076
|
var BillingInfoSchema = z2.object({
|
|
1009
1077
|
card: z2.object({ brand: z2.string(), last4: z2.string() }).nullable(),
|
|
@@ -1095,7 +1163,14 @@ var CloudHostSchema = z2.object({
|
|
|
1095
1163
|
lastSeenAt: z2.string().nullable(),
|
|
1096
1164
|
capacity: CapacitySchema.nullable(),
|
|
1097
1165
|
/** ISO 3166-1 alpha-2 code (`RO`), null when nobody said where the host is. */
|
|
1098
|
-
country: z2.string().nullable()
|
|
1166
|
+
country: z2.string().nullable(),
|
|
1167
|
+
/** kvbox-server's version as of the poller's last look (`capacity.version`); null before one, or for a server older than 0.5.45. */
|
|
1168
|
+
version: z2.string().nullable()
|
|
1169
|
+
});
|
|
1170
|
+
var HostInfoSchema = z2.object({
|
|
1171
|
+
host: CloudHostSchema,
|
|
1172
|
+
health: HealthSchema.nullable(),
|
|
1173
|
+
error: z2.string().nullable()
|
|
1099
1174
|
});
|
|
1100
1175
|
var HostPatchRequest = z2.object({ country: z2.string().nullable() });
|
|
1101
1176
|
var CountrySchema = z2.object({ code: z2.string(), name: z2.string() });
|
|
@@ -1389,6 +1464,10 @@ var ServerClient = class {
|
|
|
1389
1464
|
balance(org) {
|
|
1390
1465
|
return this.call("GET", "/billing/balance", BalanceSchema, void 0, org);
|
|
1391
1466
|
}
|
|
1467
|
+
/** Redeem a promo code (#163) for the caller's slug, or for `--org`'s org, which they own; a control plane only. */
|
|
1468
|
+
redeem(code) {
|
|
1469
|
+
return this.call("POST", "/billing/redeem", RedeemResponseSchema, { code });
|
|
1470
|
+
}
|
|
1392
1471
|
deleteMachine(name) {
|
|
1393
1472
|
return this.call("DELETE", `/machines/${encodeURIComponent(name)}`, z3.undefined());
|
|
1394
1473
|
}
|
|
@@ -1693,9 +1772,9 @@ async function select(message, choices, initial = 0) {
|
|
|
1693
1772
|
if (drawn > 0) out.write(`${ESC}[${drawn}A`);
|
|
1694
1773
|
const lines = [
|
|
1695
1774
|
`${color.green("?")} ${color.bold(message)} ${color.dim("\u2191\u2193 to move, enter to pick")}`,
|
|
1696
|
-
...choices.map((
|
|
1697
|
-
const hint =
|
|
1698
|
-
return i === index ? `${color.cyan(`\u276F ${
|
|
1775
|
+
...choices.map((c2, i) => {
|
|
1776
|
+
const hint = c2.hint ? color.dim(` ${c2.hint}`) : "";
|
|
1777
|
+
return i === index ? `${color.cyan(`\u276F ${c2.label}`)}${hint}` : ` ${c2.label}${hint}`;
|
|
1699
1778
|
})
|
|
1700
1779
|
];
|
|
1701
1780
|
out.write(`\r${ESC}[J${lines.join("\n")}
|
|
@@ -1901,7 +1980,7 @@ function parseDuration(text2) {
|
|
|
1901
1980
|
}
|
|
1902
1981
|
|
|
1903
1982
|
// src/commands/vm/new.ts
|
|
1904
|
-
var newCommand = new Command("new").description("boot a new box from an image (the base one, or e.g. postgres) or a snapshot").argument("[name]", "box name (box1, box2, \u2026 when omitted)").addOption(new Option("-s, --size <size>", "box size (default: server config, s)").choices(SIZE_NAMES)).option("-b, --base <image>", "the image to boot: base (default) or one the host has, e.g. postgres").option("-e, --env <NAME=value>", "a variable of the box's own, over yours (repeatable; change later with kvbox env set --box)", collect, []).option("-f, --from <snapshot>", "start from a snapshot instead of an image").option("--near <box>", "put it on the same host as this box, so the two can be linked (kvbox vm link)").option("--country <country>", "put it on a host in this country, a name or a code, e.g. romania or US").option("--auto-hibernate <duration>", "hibernate the box after this long without network traffic (30m, 4h, 1d; off: never; default: server config, off)").option("--force", "skip the capacity guard").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
1983
|
+
var newCommand = new Command("new").description("boot a new box from an image (the base one, or e.g. postgres) or a snapshot").argument("[name]", "box name (box1, box2, \u2026 when omitted)").addOption(new Option("-s, --size <size>", "box size (default: server config, s)").choices(SIZE_NAMES)).option("-b, --base <image>", "the image to boot: base (default) or one the host has, e.g. postgres").option("-e, --env <NAME=value>", "a variable of the box's own, over yours (repeatable; change later with kvbox env set --box)", collect, []).option("-f, --from <snapshot>", "start from a snapshot instead of an image").option("--near <box>", "put it on the same host as this box, so the two can be linked (kvbox vm link)").option("--country <country>", "put it on a host in this country, a name or a code, e.g. romania or US").addOption(new Option("--host <name>", "put it on this host and no other (admins only)").hideHelp()).option("--auto-hibernate <duration>", "hibernate the box after this long without network traffic (30m, 4h, 1d; off: never; default: server config, off)").option("--force", "skip the capacity guard").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
1905
1984
|
const autoHibernateSec = opts.autoHibernate === void 0 ? void 0 : parseIdleTimeout(opts.autoHibernate);
|
|
1906
1985
|
const env = parseEnvFlags(opts.env);
|
|
1907
1986
|
const country = opts.country === void 0 ? void 0 : parseCountry(opts.country);
|
|
@@ -1911,6 +1990,10 @@ var newCommand = new Command("new").description("boot a new box from an image (t
|
|
|
1911
1990
|
await client.close();
|
|
1912
1991
|
throw new KvboxError("--country picks a host through the control plane; this machine is the only host here (kvbox login first)");
|
|
1913
1992
|
}
|
|
1993
|
+
if (opts.host !== void 0 && client.target.kind !== "cloud") {
|
|
1994
|
+
await client.close();
|
|
1995
|
+
throw new KvboxError("--host picks a host through the control plane; this machine is the only host here (kvbox login first)");
|
|
1996
|
+
}
|
|
1914
1997
|
try {
|
|
1915
1998
|
const what = opts.from !== void 0 ? `restoring ${name ?? "a new box"} from snapshot ${opts.from}\u2026` : `booting ${name ?? "a new box"}${opts.base !== void 0 && opts.base !== "base" ? ` from image ${opts.base}` : ""}\u2026`;
|
|
1916
1999
|
const box = await spin(what, client.createMachine({
|
|
@@ -1921,6 +2004,7 @@ var newCommand = new Command("new").description("boot a new box from an image (t
|
|
|
1921
2004
|
...env.length > 0 ? { env } : {},
|
|
1922
2005
|
...opts.near !== void 0 ? { near: opts.near } : {},
|
|
1923
2006
|
...country !== void 0 ? { country } : {},
|
|
2007
|
+
...opts.host !== void 0 ? { host: opts.host } : {},
|
|
1924
2008
|
...autoHibernateSec !== void 0 ? { autoHibernateSec } : {},
|
|
1925
2009
|
...opts.force ? { force: true } : {}
|
|
1926
2010
|
}));
|
|
@@ -2072,8 +2156,8 @@ function positiveSeconds(value) {
|
|
|
2072
2156
|
async function runSsh(ssh, opts) {
|
|
2073
2157
|
const child = spawn2("ssh", ssh, { stdio: ["inherit", opts.json ? "pipe" : "inherit", opts.json ? "pipe" : "inherit"] });
|
|
2074
2158
|
const chunks = [];
|
|
2075
|
-
child.stdout?.on("data", (
|
|
2076
|
-
child.stderr?.on("data", (
|
|
2159
|
+
child.stdout?.on("data", (c2) => chunks.push(c2));
|
|
2160
|
+
child.stderr?.on("data", (c2) => chunks.push(c2));
|
|
2077
2161
|
let timedOut = false;
|
|
2078
2162
|
const timer = opts.timeout === void 0 ? void 0 : setTimeout(() => {
|
|
2079
2163
|
timedOut = true;
|
|
@@ -3016,8 +3100,8 @@ function parseSwapReport(output) {
|
|
|
3016
3100
|
function runSwap(ep, mib) {
|
|
3017
3101
|
const child = spawn3("ssh", ["-n", ...sshArgs(ep), swapCommand(mib)], { stdio: ["ignore", "pipe", "pipe"] });
|
|
3018
3102
|
const chunks = [];
|
|
3019
|
-
child.stdout.on("data", (
|
|
3020
|
-
child.stderr.on("data", (
|
|
3103
|
+
child.stdout.on("data", (c2) => chunks.push(c2));
|
|
3104
|
+
child.stderr.on("data", (c2) => chunks.push(c2));
|
|
3021
3105
|
return new Promise((resolve3, reject) => {
|
|
3022
3106
|
child.once("error", (err) => reject(new KvboxError(`could not run ssh: ${err.message}`)));
|
|
3023
3107
|
child.once("close", (code) => resolve3({ status: code ?? 1, output: Buffer.concat(chunks).toString("utf8") }));
|
|
@@ -3727,7 +3811,8 @@ async function creditLine(client, me2) {
|
|
|
3727
3811
|
}
|
|
3728
3812
|
const whose = b.slug === me2 ? "private" : b.slug;
|
|
3729
3813
|
const left = money(b.balance, b.currency);
|
|
3730
|
-
const
|
|
3814
|
+
const promo = b.promo > 0 && b.promoExpiresAt ? `, ${money(b.promo, b.currency)} of it promo credit that expires on ${day2(b.promoExpiresAt)}` : "";
|
|
3815
|
+
const line = `credit: ${b.balance > 0 ? left : color.red(left)} left${promo} ${color.dim(`(${whose})`)}`;
|
|
3731
3816
|
return b.suspendedAt ? `${line} ${color.red("out of credit: boxes hibernated until you top up")}` : line;
|
|
3732
3817
|
}
|
|
3733
3818
|
function ownerCell2(b, me2) {
|
|
@@ -3848,17 +3933,37 @@ function creditRow(b, me2) {
|
|
|
3848
3933
|
return {
|
|
3849
3934
|
owner: b.slug === me2 ? "private" : boxName(b.slug),
|
|
3850
3935
|
credit: b.balance > 0 ? left : color.red(left),
|
|
3936
|
+
promo: b.promo > 0 && b.promoExpiresAt ? `${money(b.promo, b.currency)} until ${b.promoExpiresAt.slice(0, 10)}` : "-",
|
|
3851
3937
|
"topped up": money(b.topUps, b.currency),
|
|
3852
3938
|
spent: money(b.spent, b.currency),
|
|
3853
3939
|
// Suspended (#76): the sweep hibernated the boxes at zero; a top-up brings them back.
|
|
3854
|
-
state: b.suspendedAt ? color.red("suspended") : b.since === null ? color.dim("
|
|
3940
|
+
state: b.suspendedAt ? color.red("suspended") : b.since === null ? color.dim("no credit yet") : "ok"
|
|
3855
3941
|
};
|
|
3856
3942
|
}
|
|
3857
3943
|
|
|
3944
|
+
// src/commands/redeem.ts
|
|
3945
|
+
import { Command as Command53 } from "commander";
|
|
3946
|
+
var redeemCommand = new Command53("redeem").description("redeem a promo code for credit, on your account or (--org) an org you own").argument("<code>", "the code, like KV-7F3K-9QXM-2HBD").option("--org <slug>", "give the credit to this org, which you own; it cannot be moved later").option("--json", "print as JSON").action(async (code, opts, cmd) => {
|
|
3947
|
+
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
3948
|
+
try {
|
|
3949
|
+
if (client.target.kind === "local") throw new KvboxError("codes are redeemed on the control plane: kvbox login first");
|
|
3950
|
+
const done = await client.redeem(code);
|
|
3951
|
+
if (opts.json) {
|
|
3952
|
+
json(done);
|
|
3953
|
+
return;
|
|
3954
|
+
}
|
|
3955
|
+
const whose = done.slug === client.target.user ? "your account" : `org ${done.slug}`;
|
|
3956
|
+
info(`${money(done.amount, done.currency)} of credit added to ${whose}. It is used first and expires on ${done.expiresAt.slice(0, 10)}.`);
|
|
3957
|
+
info(`credit: ${money(done.balance.balance, done.balance.currency)} left${done.reinstated ? "; you can start your boxes again" : ""}`);
|
|
3958
|
+
} finally {
|
|
3959
|
+
await client.close();
|
|
3960
|
+
}
|
|
3961
|
+
});
|
|
3962
|
+
|
|
3858
3963
|
// src/commands/deploy/index.ts
|
|
3859
3964
|
import { access as access4, readFile as readFile7 } from "fs/promises";
|
|
3860
3965
|
import { basename, resolve as resolve2 } from "path";
|
|
3861
|
-
import { Command as
|
|
3966
|
+
import { Command as Command54, InvalidArgumentError as InvalidArgumentError2, Option as Option5 } from "commander";
|
|
3862
3967
|
|
|
3863
3968
|
// src/commands/deploy/config.ts
|
|
3864
3969
|
import { readFile as readFile6, writeFile as writeFile4 } from "fs/promises";
|
|
@@ -3889,7 +3994,7 @@ function commands(pm) {
|
|
|
3889
3994
|
}
|
|
3890
3995
|
}
|
|
3891
3996
|
function serverRemote(opts) {
|
|
3892
|
-
const
|
|
3997
|
+
const c2 = commands(opts.pm);
|
|
3893
3998
|
const unit = [
|
|
3894
3999
|
"[Unit]",
|
|
3895
4000
|
"Description=kvbox deploy: the app in " + APP_DIR,
|
|
@@ -3900,7 +4005,7 @@ function serverRemote(opts) {
|
|
|
3900
4005
|
`WorkingDirectory=${APP_DIR}`,
|
|
3901
4006
|
// PORT on the command line: the proxied address points at it, and nothing in the environment
|
|
3902
4007
|
// file below may move the app off it (env's PORT, say, copied from a .env).
|
|
3903
|
-
`ExecStart=/usr/bin/env PORT=${opts.port} ${
|
|
4008
|
+
`ExecStart=/usr/bin/env PORT=${opts.port} ${c2.start}`,
|
|
3904
4009
|
"Environment=NODE_ENV=production",
|
|
3905
4010
|
// The box owner's variables (#88, base v0.10.0+; the `-` makes an older box start without them).
|
|
3906
4011
|
"EnvironmentFile=-/etc/kvbox/env",
|
|
@@ -3919,9 +4024,9 @@ function serverRemote(opts) {
|
|
|
3919
4024
|
"cd /srv/app/.incoming",
|
|
3920
4025
|
// Not NODE_ENV=production here: the install would skip devDependencies, which the build needs (TypeScript, Tailwind).
|
|
3921
4026
|
`export ${["CI=1", ...opts.env ?? []].join(" ")}`,
|
|
3922
|
-
...
|
|
3923
|
-
|
|
3924
|
-
...opts.build ? [
|
|
4027
|
+
...c2.setup,
|
|
4028
|
+
c2.install,
|
|
4029
|
+
...opts.build ? [c2.build] : [],
|
|
3925
4030
|
"cd /",
|
|
3926
4031
|
`sudo -n tee /etc/systemd/system/${SERVICE}.service >/dev/null <<'UNIT'`,
|
|
3927
4032
|
...unit,
|
|
@@ -4253,9 +4358,9 @@ async function ship(ep, dir, remote, exclude = []) {
|
|
|
4253
4358
|
const ssh = spawn5("ssh", [...sshArgs(ep), remote], { stdio: ["pipe", "pipe", "pipe"] });
|
|
4254
4359
|
tar.stdout.pipe(ssh.stdin);
|
|
4255
4360
|
const chunks = [];
|
|
4256
|
-
ssh.stdout.on("data", (
|
|
4257
|
-
ssh.stderr.on("data", (
|
|
4258
|
-
tar.stderr.on("data", (
|
|
4361
|
+
ssh.stdout.on("data", (c2) => chunks.push(c2));
|
|
4362
|
+
ssh.stderr.on("data", (c2) => chunks.push(c2));
|
|
4363
|
+
tar.stderr.on("data", (c2) => chunks.push(c2));
|
|
4259
4364
|
ssh.stdin.on("error", () => {
|
|
4260
4365
|
});
|
|
4261
4366
|
tar.stdout.on("error", () => {
|
|
@@ -4280,7 +4385,7 @@ async function ship(ep, dir, remote, exclude = []) {
|
|
|
4280
4385
|
var shipping = { ship, measure, waitForSsh };
|
|
4281
4386
|
|
|
4282
4387
|
// src/commands/deploy/index.ts
|
|
4283
|
-
var deployCommand = new
|
|
4388
|
+
var deployCommand = new Command54("deploy").description("put the app in this directory (React, Next.js, a Node server, a Dockerfile or a static site) 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 and the directory 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 box port of a Next.js app, Node server or container (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) => {
|
|
4284
4389
|
const dir = resolve2(dirArg ?? ".");
|
|
4285
4390
|
const pkg = await readPackageJson(dir);
|
|
4286
4391
|
const facts = { indexHtml: await exists(resolve2(dir, "index.html")), dockerfile: await exists(resolve2(dir, "Dockerfile")) };
|
|
@@ -4491,15 +4596,15 @@ the app is on box ${ref} but has no address yet: pick another with kvbox deploy
|
|
|
4491
4596
|
}
|
|
4492
4597
|
|
|
4493
4598
|
// src/commands/volume/index.ts
|
|
4494
|
-
import { Command as
|
|
4599
|
+
import { Command as Command60 } from "commander";
|
|
4495
4600
|
|
|
4496
4601
|
// src/commands/volume/attach.ts
|
|
4497
|
-
import { Command as
|
|
4602
|
+
import { Command as Command55 } from "commander";
|
|
4498
4603
|
function describeMount(machine, volume, box) {
|
|
4499
4604
|
const path = machine.volumes?.find((v) => volume === v.name || volume.endsWith(`/${v.name}`))?.mountPath ?? volumeMountPath(volume.slice(volume.lastIndexOf("/") + 1));
|
|
4500
4605
|
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`;
|
|
4501
4606
|
}
|
|
4502
|
-
var attachCommand = new
|
|
4607
|
+
var attachCommand = new Command55("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) => {
|
|
4503
4608
|
if (volumeArg === void 0 || boxArg === void 0) askOrUsage("give the volume and the box: kvbox volume attach <volume> <box>");
|
|
4504
4609
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4505
4610
|
try {
|
|
@@ -4518,7 +4623,7 @@ var attachCommand = new Command54("attach").description("attach a volume to a bo
|
|
|
4518
4623
|
});
|
|
4519
4624
|
|
|
4520
4625
|
// src/commands/volume/create.ts
|
|
4521
|
-
import { Command as
|
|
4626
|
+
import { Command as Command56 } from "commander";
|
|
4522
4627
|
function parseGib2(text2) {
|
|
4523
4628
|
const mib = parseMib(text2);
|
|
4524
4629
|
if (mib === void 0 || mib % 1024 !== 0) throw new KvboxError(`--size ${text2}: write whole GB, like 50 or 50GB`);
|
|
@@ -4534,7 +4639,7 @@ function sizeProblem(answer) {
|
|
|
4534
4639
|
return err instanceof KvboxError ? err.message.replace(/^--size \S+: /, "") : String(err);
|
|
4535
4640
|
}
|
|
4536
4641
|
}
|
|
4537
|
-
var createCommand3 = new
|
|
4642
|
+
var createCommand3 = new Command56("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) => {
|
|
4538
4643
|
const ask = interactive();
|
|
4539
4644
|
if (nameArg === void 0 || opts.size === void 0) askOrUsage("give the name and the size: kvbox volume create <name> --size <gb> --box <box>");
|
|
4540
4645
|
const name = nameArg ?? await text("Volume name", { validate: (a) => VOLUME_NAME_RE.test(a) ? void 0 : VOLUME_NAME_RULE });
|
|
@@ -4567,8 +4672,8 @@ var createCommand3 = new Command55("create").alias("new").description("create a
|
|
|
4567
4672
|
});
|
|
4568
4673
|
|
|
4569
4674
|
// src/commands/volume/detach.ts
|
|
4570
|
-
import { Command as
|
|
4571
|
-
var detachCommand = new
|
|
4675
|
+
import { Command as Command57 } from "commander";
|
|
4676
|
+
var detachCommand = new Command57("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) => {
|
|
4572
4677
|
if (volumeArg === void 0) askOrUsage("give the volume: kvbox volume detach <volume> [box]");
|
|
4573
4678
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4574
4679
|
try {
|
|
@@ -4593,8 +4698,8 @@ var detachCommand = new Command56("detach").description("detach a volume from a
|
|
|
4593
4698
|
});
|
|
4594
4699
|
|
|
4595
4700
|
// src/commands/volume/ls.ts
|
|
4596
|
-
import { Command as
|
|
4597
|
-
var lsCommand8 = new
|
|
4701
|
+
import { Command as Command58 } from "commander";
|
|
4702
|
+
var lsCommand8 = new Command58("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) => {
|
|
4598
4703
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4599
4704
|
try {
|
|
4600
4705
|
const cloud = client.target.kind === "cloud";
|
|
@@ -4625,8 +4730,8 @@ var lsCommand8 = new Command57("ls").alias("list").description("list volumes: si
|
|
|
4625
4730
|
});
|
|
4626
4731
|
|
|
4627
4732
|
// src/commands/volume/rm.ts
|
|
4628
|
-
import { Command as
|
|
4629
|
-
var rmCommand7 = new
|
|
4733
|
+
import { Command as Command59 } from "commander";
|
|
4734
|
+
var rmCommand7 = new Command59("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) => {
|
|
4630
4735
|
if (!await confirm(`Delete volume ${name} and everything on it?`, opts.yes ?? false)) {
|
|
4631
4736
|
info("cancelled");
|
|
4632
4737
|
process.exitCode = 1;
|
|
@@ -4642,14 +4747,14 @@ var rmCommand7 = new Command58("rm").alias("remove").description("delete a volum
|
|
|
4642
4747
|
});
|
|
4643
4748
|
|
|
4644
4749
|
// src/commands/volume/index.ts
|
|
4645
|
-
var volumeCommand = new
|
|
4750
|
+
var volumeCommand = new Command60("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(createCommand3).addCommand(lsCommand8).addCommand(attachCommand).addCommand(detachCommand).addCommand(rmCommand7);
|
|
4646
4751
|
for (const cmd of volumeCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal volumes)");
|
|
4647
4752
|
|
|
4648
4753
|
// src/commands/env/index.ts
|
|
4649
|
-
import { Command as
|
|
4754
|
+
import { Command as Command64 } from "commander";
|
|
4650
4755
|
|
|
4651
4756
|
// src/commands/env/ls.ts
|
|
4652
|
-
import { Command as
|
|
4757
|
+
import { Command as Command61 } from "commander";
|
|
4653
4758
|
|
|
4654
4759
|
// src/commands/env/shared.ts
|
|
4655
4760
|
function requireCloud4(client) {
|
|
@@ -4676,7 +4781,7 @@ function firstBootHint(box, name) {
|
|
|
4676
4781
|
}
|
|
4677
4782
|
|
|
4678
4783
|
// src/commands/env/ls.ts
|
|
4679
|
-
var lsCommand9 = new
|
|
4784
|
+
var lsCommand9 = new Command61("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) => {
|
|
4680
4785
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
4681
4786
|
try {
|
|
4682
4787
|
if (opts.box !== void 0) {
|
|
@@ -4715,8 +4820,8 @@ var lsCommand9 = new Command60("ls").alias("list").description("list the variabl
|
|
|
4715
4820
|
});
|
|
4716
4821
|
|
|
4717
4822
|
// src/commands/env/rm.ts
|
|
4718
|
-
import { Command as
|
|
4719
|
-
var rmCommand8 = new
|
|
4823
|
+
import { Command as Command62 } from "commander";
|
|
4824
|
+
var rmCommand8 = new Command62("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 (names2, opts, cmd) => {
|
|
4720
4825
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
4721
4826
|
try {
|
|
4722
4827
|
const target = opts.box === void 0 ? void 0 : await findBox2(client, opts.box);
|
|
@@ -4731,14 +4836,14 @@ var rmCommand8 = new Command61("rm").alias("remove").description("remove variabl
|
|
|
4731
4836
|
for (const name of names2) {
|
|
4732
4837
|
try {
|
|
4733
4838
|
if (target !== void 0) {
|
|
4734
|
-
const
|
|
4735
|
-
changes.push(
|
|
4736
|
-
if (!opts.json) info(`${color.green("\u2713")} removed ${
|
|
4839
|
+
const c3 = await spin(`removing ${name}\u2026`, client.removeBoxEnv(target.ref, name));
|
|
4840
|
+
changes.push(c3);
|
|
4841
|
+
if (!opts.json) info(`${color.green("\u2713")} removed ${c3.name} from ${owner}: ${boxReach(c3.running, "loses")}`);
|
|
4737
4842
|
continue;
|
|
4738
4843
|
}
|
|
4739
|
-
const
|
|
4740
|
-
changes.push(
|
|
4741
|
-
if (!opts.json) info(`${color.green("\u2713")} removed ${
|
|
4844
|
+
const c2 = await spin(`removing ${name}\u2026`, client.removeEnv(name));
|
|
4845
|
+
changes.push(c2);
|
|
4846
|
+
if (!opts.json) info(`${color.green("\u2713")} removed ${c2.name} from ${owner}: ${reach(c2.boxes, "lose")}`);
|
|
4742
4847
|
} catch (err) {
|
|
4743
4848
|
failed.push({ name, err });
|
|
4744
4849
|
}
|
|
@@ -4753,8 +4858,8 @@ var rmCommand8 = new Command61("rm").alias("remove").description("remove variabl
|
|
|
4753
4858
|
});
|
|
4754
4859
|
|
|
4755
4860
|
// src/commands/env/set.ts
|
|
4756
|
-
import { Command as
|
|
4757
|
-
var setCommand2 = new
|
|
4861
|
+
import { Command as Command63 } from "commander";
|
|
4862
|
+
var setCommand2 = new Command63("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) => {
|
|
4758
4863
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
4759
4864
|
try {
|
|
4760
4865
|
const owner = opts.box === void 0 ? requireCloud4(client) : void 0;
|
|
@@ -4791,14 +4896,14 @@ var setCommand2 = new Command62("set").description("add or change a variable; bo
|
|
|
4791
4896
|
});
|
|
4792
4897
|
|
|
4793
4898
|
// src/commands/env/index.ts
|
|
4794
|
-
var envCommand = new
|
|
4899
|
+
var envCommand = new Command64("env").description("environment variables every box of yours gets when it starts (secrets too)").addCommand(lsCommand9, { isDefault: true }).addCommand(setCommand2).addCommand(rmCommand8);
|
|
4795
4900
|
for (const cmd of envCommand.commands) cmd.option("--org <slug>", "the org's variables instead of yours");
|
|
4796
4901
|
|
|
4797
4902
|
// src/commands/domain/index.ts
|
|
4798
|
-
import { Command as
|
|
4903
|
+
import { Command as Command68 } from "commander";
|
|
4799
4904
|
|
|
4800
4905
|
// src/commands/domain/add.ts
|
|
4801
|
-
import { Command as
|
|
4906
|
+
import { Command as Command65 } from "commander";
|
|
4802
4907
|
|
|
4803
4908
|
// src/commands/domain/shared.ts
|
|
4804
4909
|
function requireCloud5(client) {
|
|
@@ -4818,7 +4923,7 @@ function hostIn(name, zone) {
|
|
|
4818
4923
|
}
|
|
4819
4924
|
|
|
4820
4925
|
// src/commands/domain/add.ts
|
|
4821
|
-
var addCommand3 = new
|
|
4926
|
+
var addCommand3 = new Command65("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) => {
|
|
4822
4927
|
const domain = assertDomain(domainArg.trim().toLowerCase());
|
|
4823
4928
|
const port = opts.port === void 0 ? void 0 : parsePorts([opts.port])[0];
|
|
4824
4929
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
@@ -4854,8 +4959,8 @@ kvbox checks every minute; ${domain} is served at ${d.url} once its records are
|
|
|
4854
4959
|
});
|
|
4855
4960
|
|
|
4856
4961
|
// src/commands/domain/ls.ts
|
|
4857
|
-
import { Command as
|
|
4858
|
-
var lsCommand10 = new
|
|
4962
|
+
import { Command as Command66 } from "commander";
|
|
4963
|
+
var lsCommand10 = new Command66("ls").alias("list").description("list your custom domains and whether they are live").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
4859
4964
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4860
4965
|
try {
|
|
4861
4966
|
requireCloud5(client);
|
|
@@ -4884,8 +4989,8 @@ var lsCommand10 = new Command65("ls").alias("list").description("list your custo
|
|
|
4884
4989
|
});
|
|
4885
4990
|
|
|
4886
4991
|
// src/commands/domain/rm.ts
|
|
4887
|
-
import { Command as
|
|
4888
|
-
var rmCommand9 = new
|
|
4992
|
+
import { Command as Command67 } from "commander";
|
|
4993
|
+
var rmCommand9 = new Command67("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) => {
|
|
4889
4994
|
const domain = domainArg.trim().toLowerCase();
|
|
4890
4995
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4891
4996
|
try {
|
|
@@ -4906,7 +5011,7 @@ var rmCommand9 = new Command66("rm").alias("remove").description("stop serving a
|
|
|
4906
5011
|
});
|
|
4907
5012
|
|
|
4908
5013
|
// src/commands/domain/index.ts
|
|
4909
|
-
var domainCommand = new
|
|
5014
|
+
var domainCommand = new Command68("domain").alias("domains").description("serve a box at a domain of your own").addCommand(addCommand3).addCommand(lsCommand10).addCommand(rmCommand9);
|
|
4910
5015
|
for (const cmd of domainCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
4911
5016
|
|
|
4912
5017
|
// src/commands/update.ts
|
|
@@ -4914,7 +5019,7 @@ import { spawn as spawn6 } from "child_process";
|
|
|
4914
5019
|
import { mkdtempSync, rmSync, writeFileSync as writeFileSync2 } from "fs";
|
|
4915
5020
|
import { tmpdir } from "os";
|
|
4916
5021
|
import { join as join8 } from "path";
|
|
4917
|
-
import { Command as
|
|
5022
|
+
import { Command as Command69 } from "commander";
|
|
4918
5023
|
|
|
4919
5024
|
// src/update.ts
|
|
4920
5025
|
import { mkdirSync, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
@@ -5033,7 +5138,7 @@ function run(cmd, args) {
|
|
|
5033
5138
|
child.on("exit", (code, signal) => resolve3(code ?? (signal ? 1 : 0)));
|
|
5034
5139
|
});
|
|
5035
5140
|
}
|
|
5036
|
-
var selfUpdateCommand = new
|
|
5141
|
+
var selfUpdateCommand = new Command69("update").description("update kvbox to the latest version (reruns the installer from kvbox.sh, agent skill included)").action(async () => {
|
|
5037
5142
|
suppressUpdateNotice();
|
|
5038
5143
|
const inst = installerFor(process.platform, process.env["KVBOX_INSTALL_URL"] || INSTALL_BASE);
|
|
5039
5144
|
let code;
|
|
@@ -5053,9 +5158,108 @@ var selfUpdateCommand = new Command68("update").description("update kvbox to the
|
|
|
5053
5158
|
if (code !== 0) throw new KvboxError(`the installer failed (exit ${code})`, code);
|
|
5054
5159
|
});
|
|
5055
5160
|
|
|
5161
|
+
// src/help.ts
|
|
5162
|
+
import pc2 from "picocolors";
|
|
5163
|
+
var c = pc2.createColors(true);
|
|
5164
|
+
var TAGLINE = "microVMs with Docker-like ergonomics";
|
|
5165
|
+
var LOGO = [
|
|
5166
|
+
"\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2557",
|
|
5167
|
+
"\u2588\u2588\u2551 \u2588\u2588\u2554\u255D\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2550\u2588\u2588\u2557\u255A\u2588\u2588\u2557\u2588\u2588\u2554\u255D",
|
|
5168
|
+
"\u2588\u2588\u2588\u2588\u2588\u2554\u255D \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551 \u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2554\u255D",
|
|
5169
|
+
"\u2588\u2588\u2554\u2550\u2588\u2588\u2557 \u255A\u2588\u2588\u2557 \u2588\u2588\u2554\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2554\u2588\u2588\u2557",
|
|
5170
|
+
"\u2588\u2588\u2551 \u2588\u2588\u2557 \u255A\u2588\u2588\u2588\u2588\u2554\u255D \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2554\u255D \u2588\u2588\u2557",
|
|
5171
|
+
"\u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D"
|
|
5172
|
+
];
|
|
5173
|
+
var LOGO_WIDTH = 42;
|
|
5174
|
+
var HELP_GROUPS = [
|
|
5175
|
+
{
|
|
5176
|
+
title: "Everyday",
|
|
5177
|
+
commands: [
|
|
5178
|
+
["new", "boot a new box from an image or a snapshot"],
|
|
5179
|
+
["ls", "list your boxes with status and address"],
|
|
5180
|
+
["get", "show one box in full"],
|
|
5181
|
+
["connect", "open a shell in a box, or run a command there (short: cn)"],
|
|
5182
|
+
["exec", "run a command in a box and exit with its status"],
|
|
5183
|
+
["claim", "give a box an HTTPS address, https://<name>.kvbox.app"],
|
|
5184
|
+
["deploy", "put the app in this directory on a box with its own HTTPS address"],
|
|
5185
|
+
["rm", "destroy a box and its disk"]
|
|
5186
|
+
]
|
|
5187
|
+
},
|
|
5188
|
+
{
|
|
5189
|
+
title: "Stop and continue",
|
|
5190
|
+
commands: [
|
|
5191
|
+
["stop", "shut a box down, keeping its disk"],
|
|
5192
|
+
["start", "boot a stopped box again"],
|
|
5193
|
+
["pause", "freeze a box in place, memory kept"],
|
|
5194
|
+
["resume", "continue a paused box"],
|
|
5195
|
+
["hibernate", "save a box's memory to disk and free its RAM"],
|
|
5196
|
+
["wake", "continue a hibernated box where it left off"]
|
|
5197
|
+
]
|
|
5198
|
+
},
|
|
5199
|
+
{
|
|
5200
|
+
title: "Manage",
|
|
5201
|
+
commands: [
|
|
5202
|
+
["vm", "everything about boxes: fork, rescale, ports, hooks, backups"],
|
|
5203
|
+
["snapshots", "freeze a running box into a snapshot, start new boxes from it"],
|
|
5204
|
+
["volume", "disks of their own that move between boxes"],
|
|
5205
|
+
["env", "environment variables and secrets every box of yours gets"],
|
|
5206
|
+
["domain", "serve a box at a domain of your own"]
|
|
5207
|
+
]
|
|
5208
|
+
},
|
|
5209
|
+
{
|
|
5210
|
+
title: "Account",
|
|
5211
|
+
commands: [
|
|
5212
|
+
["login", "log in to the kvbox cloud or your own control plane"],
|
|
5213
|
+
["logout", "log out; commands target this machine again"],
|
|
5214
|
+
["whoami", "show the account and control plane in use"],
|
|
5215
|
+
["org", "shared slugs that own boxes, with owners, admins and members"],
|
|
5216
|
+
["usage", "what your boxes and volumes used, and what it cost"],
|
|
5217
|
+
["credit", "the prepaid credit left on your account and orgs"],
|
|
5218
|
+
["redeem", "redeem a promo code for credit"],
|
|
5219
|
+
["update", "update kvbox to the latest version"]
|
|
5220
|
+
]
|
|
5221
|
+
}
|
|
5222
|
+
];
|
|
5223
|
+
function banner(stream) {
|
|
5224
|
+
if (stream.isTTY !== true || (stream.columns || 80) < LOGO_WIDTH + 2) return `kvbox ${VERSION} \xB7 ${TAGLINE}
|
|
5225
|
+
`;
|
|
5226
|
+
return ["", ...LOGO.map((line) => c.blue(line)), c.dim(` v${VERSION} \xB7 ${TAGLINE}`), ""].join("\n");
|
|
5227
|
+
}
|
|
5228
|
+
function formatRootHelp(cmd, helper) {
|
|
5229
|
+
const visible = new Map(helper.visibleCommands(cmd).map((sub) => [sub.name(), sub]));
|
|
5230
|
+
const groups = HELP_GROUPS.map((g) => ({
|
|
5231
|
+
title: g.title,
|
|
5232
|
+
items: g.commands.filter(([name]) => visible.delete(name))
|
|
5233
|
+
}));
|
|
5234
|
+
const help = visible.get("help");
|
|
5235
|
+
visible.delete("help");
|
|
5236
|
+
const other = [...visible.values()].map((sub) => [sub.name(), helper.subcommandDescription(sub)]);
|
|
5237
|
+
if (other.length > 0) groups.push({ title: "Other", items: other });
|
|
5238
|
+
if (help) groups.at(-1).items.push(["help", "show the help of a command"]);
|
|
5239
|
+
const options = helper.visibleOptions(cmd).map((o) => [helper.optionTerm(o), helper.optionDescription(o)]);
|
|
5240
|
+
const termWidth = Math.max(...groups.flatMap((g) => g.items).map(([term]) => term.length), ...options.map(([term]) => term.length));
|
|
5241
|
+
const section = (title, items) => [
|
|
5242
|
+
c.bold(title),
|
|
5243
|
+
...items.map(([term, text2]) => helper.formatItem(c.cyan(term), termWidth, text2, helper)),
|
|
5244
|
+
""
|
|
5245
|
+
];
|
|
5246
|
+
return [
|
|
5247
|
+
`${c.bold("Usage:")} ${helper.commandUsage(cmd)}`,
|
|
5248
|
+
"",
|
|
5249
|
+
...groups.filter((g) => g.items.length > 0).flatMap((g) => section(g.title, g.items)),
|
|
5250
|
+
...section("Options", options),
|
|
5251
|
+
c.dim("kvbox <command> --help shows one command in full. Docs: https://kvbox.sh/docs"),
|
|
5252
|
+
""
|
|
5253
|
+
].join("\n");
|
|
5254
|
+
}
|
|
5255
|
+
function installRootHelp(program) {
|
|
5256
|
+
program.configureHelp({ formatHelp: formatRootHelp });
|
|
5257
|
+
program.addHelpText("before", (ctx) => banner(ctx.error ? process.stderr : process.stdout));
|
|
5258
|
+
}
|
|
5259
|
+
|
|
5056
5260
|
// src/program.ts
|
|
5057
5261
|
function buildProgram() {
|
|
5058
|
-
const program = new
|
|
5262
|
+
const program = new Command70("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();
|
|
5059
5263
|
program.addCommand(vmCommand);
|
|
5060
5264
|
program.addCommand(snapshotsCommand);
|
|
5061
5265
|
program.addCommand(volumeCommand);
|
|
@@ -5067,9 +5271,11 @@ function buildProgram() {
|
|
|
5067
5271
|
program.addCommand(orgCommand);
|
|
5068
5272
|
program.addCommand(usageCommand2);
|
|
5069
5273
|
program.addCommand(creditCommand);
|
|
5274
|
+
program.addCommand(redeemCommand);
|
|
5070
5275
|
program.addCommand(deployCommand);
|
|
5071
5276
|
program.addCommand(selfUpdateCommand);
|
|
5072
5277
|
for (const cmd of vmAliases) program.addCommand(cmd);
|
|
5278
|
+
installRootHelp(program);
|
|
5073
5279
|
return program;
|
|
5074
5280
|
}
|
|
5075
5281
|
|