@kvbox/cli 0.5.45 → 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 +242 -65
- 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";
|
|
@@ -701,6 +701,11 @@ var CreateMachineRequest = z2.object({
|
|
|
701
701
|
* `@kvbox/shared/country`. Only the control plane reads it.
|
|
702
702
|
*/
|
|
703
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(),
|
|
704
709
|
/** The image to boot (#87, `kvbox new --base postgres`). Absent: the base image. */
|
|
705
710
|
image: z2.string().optional(),
|
|
706
711
|
/** The box's own environment variables (#87, `kvbox new -e NAME=value`), over its owner's. */
|
|
@@ -967,7 +972,9 @@ var CloudUserSchema = z2.object({
|
|
|
967
972
|
* gates nobody, hence the defaults: a newer CLI must still parse its answers.
|
|
968
973
|
*/
|
|
969
974
|
active: z2.boolean().default(true),
|
|
970
|
-
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)
|
|
971
978
|
});
|
|
972
979
|
var ORG_ROLES = ["owner", "admin", "member"];
|
|
973
980
|
var OrgRoleSchema = z2.enum(ORG_ROLES);
|
|
@@ -1005,10 +1012,14 @@ var BalanceSchema = z2.object({
|
|
|
1005
1012
|
currency: z2.string(),
|
|
1006
1013
|
topUps: z2.number(),
|
|
1007
1014
|
spent: z2.number(),
|
|
1008
|
-
/** 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. */
|
|
1009
1016
|
since: z2.string().nullable(),
|
|
1010
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. */
|
|
1011
|
-
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)
|
|
1012
1023
|
});
|
|
1013
1024
|
var TopUpRequestSchema = z2.object({
|
|
1014
1025
|
slug: z2.string().min(1),
|
|
@@ -1026,6 +1037,41 @@ var TopUpSchema = z2.object({
|
|
|
1026
1037
|
note: z2.string().nullable(),
|
|
1027
1038
|
at: z2.string()
|
|
1028
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
|
+
});
|
|
1029
1075
|
var TOP_UP_AMOUNTS = [10, 25, 50, 100];
|
|
1030
1076
|
var BillingInfoSchema = z2.object({
|
|
1031
1077
|
card: z2.object({ brand: z2.string(), last4: z2.string() }).nullable(),
|
|
@@ -1418,6 +1464,10 @@ var ServerClient = class {
|
|
|
1418
1464
|
balance(org) {
|
|
1419
1465
|
return this.call("GET", "/billing/balance", BalanceSchema, void 0, org);
|
|
1420
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
|
+
}
|
|
1421
1471
|
deleteMachine(name) {
|
|
1422
1472
|
return this.call("DELETE", `/machines/${encodeURIComponent(name)}`, z3.undefined());
|
|
1423
1473
|
}
|
|
@@ -1722,9 +1772,9 @@ async function select(message, choices, initial = 0) {
|
|
|
1722
1772
|
if (drawn > 0) out.write(`${ESC}[${drawn}A`);
|
|
1723
1773
|
const lines = [
|
|
1724
1774
|
`${color.green("?")} ${color.bold(message)} ${color.dim("\u2191\u2193 to move, enter to pick")}`,
|
|
1725
|
-
...choices.map((
|
|
1726
|
-
const hint =
|
|
1727
|
-
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}`;
|
|
1728
1778
|
})
|
|
1729
1779
|
];
|
|
1730
1780
|
out.write(`\r${ESC}[J${lines.join("\n")}
|
|
@@ -1930,7 +1980,7 @@ function parseDuration(text2) {
|
|
|
1930
1980
|
}
|
|
1931
1981
|
|
|
1932
1982
|
// src/commands/vm/new.ts
|
|
1933
|
-
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) => {
|
|
1934
1984
|
const autoHibernateSec = opts.autoHibernate === void 0 ? void 0 : parseIdleTimeout(opts.autoHibernate);
|
|
1935
1985
|
const env = parseEnvFlags(opts.env);
|
|
1936
1986
|
const country = opts.country === void 0 ? void 0 : parseCountry(opts.country);
|
|
@@ -1940,6 +1990,10 @@ var newCommand = new Command("new").description("boot a new box from an image (t
|
|
|
1940
1990
|
await client.close();
|
|
1941
1991
|
throw new KvboxError("--country picks a host through the control plane; this machine is the only host here (kvbox login first)");
|
|
1942
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
|
+
}
|
|
1943
1997
|
try {
|
|
1944
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`;
|
|
1945
1999
|
const box = await spin(what, client.createMachine({
|
|
@@ -1950,6 +2004,7 @@ var newCommand = new Command("new").description("boot a new box from an image (t
|
|
|
1950
2004
|
...env.length > 0 ? { env } : {},
|
|
1951
2005
|
...opts.near !== void 0 ? { near: opts.near } : {},
|
|
1952
2006
|
...country !== void 0 ? { country } : {},
|
|
2007
|
+
...opts.host !== void 0 ? { host: opts.host } : {},
|
|
1953
2008
|
...autoHibernateSec !== void 0 ? { autoHibernateSec } : {},
|
|
1954
2009
|
...opts.force ? { force: true } : {}
|
|
1955
2010
|
}));
|
|
@@ -2101,8 +2156,8 @@ function positiveSeconds(value) {
|
|
|
2101
2156
|
async function runSsh(ssh, opts) {
|
|
2102
2157
|
const child = spawn2("ssh", ssh, { stdio: ["inherit", opts.json ? "pipe" : "inherit", opts.json ? "pipe" : "inherit"] });
|
|
2103
2158
|
const chunks = [];
|
|
2104
|
-
child.stdout?.on("data", (
|
|
2105
|
-
child.stderr?.on("data", (
|
|
2159
|
+
child.stdout?.on("data", (c2) => chunks.push(c2));
|
|
2160
|
+
child.stderr?.on("data", (c2) => chunks.push(c2));
|
|
2106
2161
|
let timedOut = false;
|
|
2107
2162
|
const timer = opts.timeout === void 0 ? void 0 : setTimeout(() => {
|
|
2108
2163
|
timedOut = true;
|
|
@@ -3045,8 +3100,8 @@ function parseSwapReport(output) {
|
|
|
3045
3100
|
function runSwap(ep, mib) {
|
|
3046
3101
|
const child = spawn3("ssh", ["-n", ...sshArgs(ep), swapCommand(mib)], { stdio: ["ignore", "pipe", "pipe"] });
|
|
3047
3102
|
const chunks = [];
|
|
3048
|
-
child.stdout.on("data", (
|
|
3049
|
-
child.stderr.on("data", (
|
|
3103
|
+
child.stdout.on("data", (c2) => chunks.push(c2));
|
|
3104
|
+
child.stderr.on("data", (c2) => chunks.push(c2));
|
|
3050
3105
|
return new Promise((resolve3, reject) => {
|
|
3051
3106
|
child.once("error", (err) => reject(new KvboxError(`could not run ssh: ${err.message}`)));
|
|
3052
3107
|
child.once("close", (code) => resolve3({ status: code ?? 1, output: Buffer.concat(chunks).toString("utf8") }));
|
|
@@ -3756,7 +3811,8 @@ async function creditLine(client, me2) {
|
|
|
3756
3811
|
}
|
|
3757
3812
|
const whose = b.slug === me2 ? "private" : b.slug;
|
|
3758
3813
|
const left = money(b.balance, b.currency);
|
|
3759
|
-
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})`)}`;
|
|
3760
3816
|
return b.suspendedAt ? `${line} ${color.red("out of credit: boxes hibernated until you top up")}` : line;
|
|
3761
3817
|
}
|
|
3762
3818
|
function ownerCell2(b, me2) {
|
|
@@ -3877,17 +3933,37 @@ function creditRow(b, me2) {
|
|
|
3877
3933
|
return {
|
|
3878
3934
|
owner: b.slug === me2 ? "private" : boxName(b.slug),
|
|
3879
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)}` : "-",
|
|
3880
3937
|
"topped up": money(b.topUps, b.currency),
|
|
3881
3938
|
spent: money(b.spent, b.currency),
|
|
3882
3939
|
// Suspended (#76): the sweep hibernated the boxes at zero; a top-up brings them back.
|
|
3883
|
-
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"
|
|
3884
3941
|
};
|
|
3885
3942
|
}
|
|
3886
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
|
+
|
|
3887
3963
|
// src/commands/deploy/index.ts
|
|
3888
3964
|
import { access as access4, readFile as readFile7 } from "fs/promises";
|
|
3889
3965
|
import { basename, resolve as resolve2 } from "path";
|
|
3890
|
-
import { Command as
|
|
3966
|
+
import { Command as Command54, InvalidArgumentError as InvalidArgumentError2, Option as Option5 } from "commander";
|
|
3891
3967
|
|
|
3892
3968
|
// src/commands/deploy/config.ts
|
|
3893
3969
|
import { readFile as readFile6, writeFile as writeFile4 } from "fs/promises";
|
|
@@ -3918,7 +3994,7 @@ function commands(pm) {
|
|
|
3918
3994
|
}
|
|
3919
3995
|
}
|
|
3920
3996
|
function serverRemote(opts) {
|
|
3921
|
-
const
|
|
3997
|
+
const c2 = commands(opts.pm);
|
|
3922
3998
|
const unit = [
|
|
3923
3999
|
"[Unit]",
|
|
3924
4000
|
"Description=kvbox deploy: the app in " + APP_DIR,
|
|
@@ -3929,7 +4005,7 @@ function serverRemote(opts) {
|
|
|
3929
4005
|
`WorkingDirectory=${APP_DIR}`,
|
|
3930
4006
|
// PORT on the command line: the proxied address points at it, and nothing in the environment
|
|
3931
4007
|
// file below may move the app off it (env's PORT, say, copied from a .env).
|
|
3932
|
-
`ExecStart=/usr/bin/env PORT=${opts.port} ${
|
|
4008
|
+
`ExecStart=/usr/bin/env PORT=${opts.port} ${c2.start}`,
|
|
3933
4009
|
"Environment=NODE_ENV=production",
|
|
3934
4010
|
// The box owner's variables (#88, base v0.10.0+; the `-` makes an older box start without them).
|
|
3935
4011
|
"EnvironmentFile=-/etc/kvbox/env",
|
|
@@ -3948,9 +4024,9 @@ function serverRemote(opts) {
|
|
|
3948
4024
|
"cd /srv/app/.incoming",
|
|
3949
4025
|
// Not NODE_ENV=production here: the install would skip devDependencies, which the build needs (TypeScript, Tailwind).
|
|
3950
4026
|
`export ${["CI=1", ...opts.env ?? []].join(" ")}`,
|
|
3951
|
-
...
|
|
3952
|
-
|
|
3953
|
-
...opts.build ? [
|
|
4027
|
+
...c2.setup,
|
|
4028
|
+
c2.install,
|
|
4029
|
+
...opts.build ? [c2.build] : [],
|
|
3954
4030
|
"cd /",
|
|
3955
4031
|
`sudo -n tee /etc/systemd/system/${SERVICE}.service >/dev/null <<'UNIT'`,
|
|
3956
4032
|
...unit,
|
|
@@ -4282,9 +4358,9 @@ async function ship(ep, dir, remote, exclude = []) {
|
|
|
4282
4358
|
const ssh = spawn5("ssh", [...sshArgs(ep), remote], { stdio: ["pipe", "pipe", "pipe"] });
|
|
4283
4359
|
tar.stdout.pipe(ssh.stdin);
|
|
4284
4360
|
const chunks = [];
|
|
4285
|
-
ssh.stdout.on("data", (
|
|
4286
|
-
ssh.stderr.on("data", (
|
|
4287
|
-
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));
|
|
4288
4364
|
ssh.stdin.on("error", () => {
|
|
4289
4365
|
});
|
|
4290
4366
|
tar.stdout.on("error", () => {
|
|
@@ -4309,7 +4385,7 @@ async function ship(ep, dir, remote, exclude = []) {
|
|
|
4309
4385
|
var shipping = { ship, measure, waitForSsh };
|
|
4310
4386
|
|
|
4311
4387
|
// src/commands/deploy/index.ts
|
|
4312
|
-
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) => {
|
|
4313
4389
|
const dir = resolve2(dirArg ?? ".");
|
|
4314
4390
|
const pkg = await readPackageJson(dir);
|
|
4315
4391
|
const facts = { indexHtml: await exists(resolve2(dir, "index.html")), dockerfile: await exists(resolve2(dir, "Dockerfile")) };
|
|
@@ -4520,15 +4596,15 @@ the app is on box ${ref} but has no address yet: pick another with kvbox deploy
|
|
|
4520
4596
|
}
|
|
4521
4597
|
|
|
4522
4598
|
// src/commands/volume/index.ts
|
|
4523
|
-
import { Command as
|
|
4599
|
+
import { Command as Command60 } from "commander";
|
|
4524
4600
|
|
|
4525
4601
|
// src/commands/volume/attach.ts
|
|
4526
|
-
import { Command as
|
|
4602
|
+
import { Command as Command55 } from "commander";
|
|
4527
4603
|
function describeMount(machine, volume, box) {
|
|
4528
4604
|
const path = machine.volumes?.find((v) => volume === v.name || volume.endsWith(`/${v.name}`))?.mountPath ?? volumeMountPath(volume.slice(volume.lastIndexOf("/") + 1));
|
|
4529
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`;
|
|
4530
4606
|
}
|
|
4531
|
-
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) => {
|
|
4532
4608
|
if (volumeArg === void 0 || boxArg === void 0) askOrUsage("give the volume and the box: kvbox volume attach <volume> <box>");
|
|
4533
4609
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4534
4610
|
try {
|
|
@@ -4547,7 +4623,7 @@ var attachCommand = new Command54("attach").description("attach a volume to a bo
|
|
|
4547
4623
|
});
|
|
4548
4624
|
|
|
4549
4625
|
// src/commands/volume/create.ts
|
|
4550
|
-
import { Command as
|
|
4626
|
+
import { Command as Command56 } from "commander";
|
|
4551
4627
|
function parseGib2(text2) {
|
|
4552
4628
|
const mib = parseMib(text2);
|
|
4553
4629
|
if (mib === void 0 || mib % 1024 !== 0) throw new KvboxError(`--size ${text2}: write whole GB, like 50 or 50GB`);
|
|
@@ -4563,7 +4639,7 @@ function sizeProblem(answer) {
|
|
|
4563
4639
|
return err instanceof KvboxError ? err.message.replace(/^--size \S+: /, "") : String(err);
|
|
4564
4640
|
}
|
|
4565
4641
|
}
|
|
4566
|
-
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) => {
|
|
4567
4643
|
const ask = interactive();
|
|
4568
4644
|
if (nameArg === void 0 || opts.size === void 0) askOrUsage("give the name and the size: kvbox volume create <name> --size <gb> --box <box>");
|
|
4569
4645
|
const name = nameArg ?? await text("Volume name", { validate: (a) => VOLUME_NAME_RE.test(a) ? void 0 : VOLUME_NAME_RULE });
|
|
@@ -4596,8 +4672,8 @@ var createCommand3 = new Command55("create").alias("new").description("create a
|
|
|
4596
4672
|
});
|
|
4597
4673
|
|
|
4598
4674
|
// src/commands/volume/detach.ts
|
|
4599
|
-
import { Command as
|
|
4600
|
-
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) => {
|
|
4601
4677
|
if (volumeArg === void 0) askOrUsage("give the volume: kvbox volume detach <volume> [box]");
|
|
4602
4678
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4603
4679
|
try {
|
|
@@ -4622,8 +4698,8 @@ var detachCommand = new Command56("detach").description("detach a volume from a
|
|
|
4622
4698
|
});
|
|
4623
4699
|
|
|
4624
4700
|
// src/commands/volume/ls.ts
|
|
4625
|
-
import { Command as
|
|
4626
|
-
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) => {
|
|
4627
4703
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4628
4704
|
try {
|
|
4629
4705
|
const cloud = client.target.kind === "cloud";
|
|
@@ -4654,8 +4730,8 @@ var lsCommand8 = new Command57("ls").alias("list").description("list volumes: si
|
|
|
4654
4730
|
});
|
|
4655
4731
|
|
|
4656
4732
|
// src/commands/volume/rm.ts
|
|
4657
|
-
import { Command as
|
|
4658
|
-
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) => {
|
|
4659
4735
|
if (!await confirm(`Delete volume ${name} and everything on it?`, opts.yes ?? false)) {
|
|
4660
4736
|
info("cancelled");
|
|
4661
4737
|
process.exitCode = 1;
|
|
@@ -4671,14 +4747,14 @@ var rmCommand7 = new Command58("rm").alias("remove").description("delete a volum
|
|
|
4671
4747
|
});
|
|
4672
4748
|
|
|
4673
4749
|
// src/commands/volume/index.ts
|
|
4674
|
-
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);
|
|
4675
4751
|
for (const cmd of volumeCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal volumes)");
|
|
4676
4752
|
|
|
4677
4753
|
// src/commands/env/index.ts
|
|
4678
|
-
import { Command as
|
|
4754
|
+
import { Command as Command64 } from "commander";
|
|
4679
4755
|
|
|
4680
4756
|
// src/commands/env/ls.ts
|
|
4681
|
-
import { Command as
|
|
4757
|
+
import { Command as Command61 } from "commander";
|
|
4682
4758
|
|
|
4683
4759
|
// src/commands/env/shared.ts
|
|
4684
4760
|
function requireCloud4(client) {
|
|
@@ -4705,7 +4781,7 @@ function firstBootHint(box, name) {
|
|
|
4705
4781
|
}
|
|
4706
4782
|
|
|
4707
4783
|
// src/commands/env/ls.ts
|
|
4708
|
-
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) => {
|
|
4709
4785
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
4710
4786
|
try {
|
|
4711
4787
|
if (opts.box !== void 0) {
|
|
@@ -4744,8 +4820,8 @@ var lsCommand9 = new Command60("ls").alias("list").description("list the variabl
|
|
|
4744
4820
|
});
|
|
4745
4821
|
|
|
4746
4822
|
// src/commands/env/rm.ts
|
|
4747
|
-
import { Command as
|
|
4748
|
-
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) => {
|
|
4749
4825
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
4750
4826
|
try {
|
|
4751
4827
|
const target = opts.box === void 0 ? void 0 : await findBox2(client, opts.box);
|
|
@@ -4760,14 +4836,14 @@ var rmCommand8 = new Command61("rm").alias("remove").description("remove variabl
|
|
|
4760
4836
|
for (const name of names2) {
|
|
4761
4837
|
try {
|
|
4762
4838
|
if (target !== void 0) {
|
|
4763
|
-
const
|
|
4764
|
-
changes.push(
|
|
4765
|
-
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")}`);
|
|
4766
4842
|
continue;
|
|
4767
4843
|
}
|
|
4768
|
-
const
|
|
4769
|
-
changes.push(
|
|
4770
|
-
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")}`);
|
|
4771
4847
|
} catch (err) {
|
|
4772
4848
|
failed.push({ name, err });
|
|
4773
4849
|
}
|
|
@@ -4782,8 +4858,8 @@ var rmCommand8 = new Command61("rm").alias("remove").description("remove variabl
|
|
|
4782
4858
|
});
|
|
4783
4859
|
|
|
4784
4860
|
// src/commands/env/set.ts
|
|
4785
|
-
import { Command as
|
|
4786
|
-
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) => {
|
|
4787
4863
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
4788
4864
|
try {
|
|
4789
4865
|
const owner = opts.box === void 0 ? requireCloud4(client) : void 0;
|
|
@@ -4820,14 +4896,14 @@ var setCommand2 = new Command62("set").description("add or change a variable; bo
|
|
|
4820
4896
|
});
|
|
4821
4897
|
|
|
4822
4898
|
// src/commands/env/index.ts
|
|
4823
|
-
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);
|
|
4824
4900
|
for (const cmd of envCommand.commands) cmd.option("--org <slug>", "the org's variables instead of yours");
|
|
4825
4901
|
|
|
4826
4902
|
// src/commands/domain/index.ts
|
|
4827
|
-
import { Command as
|
|
4903
|
+
import { Command as Command68 } from "commander";
|
|
4828
4904
|
|
|
4829
4905
|
// src/commands/domain/add.ts
|
|
4830
|
-
import { Command as
|
|
4906
|
+
import { Command as Command65 } from "commander";
|
|
4831
4907
|
|
|
4832
4908
|
// src/commands/domain/shared.ts
|
|
4833
4909
|
function requireCloud5(client) {
|
|
@@ -4847,7 +4923,7 @@ function hostIn(name, zone) {
|
|
|
4847
4923
|
}
|
|
4848
4924
|
|
|
4849
4925
|
// src/commands/domain/add.ts
|
|
4850
|
-
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) => {
|
|
4851
4927
|
const domain = assertDomain(domainArg.trim().toLowerCase());
|
|
4852
4928
|
const port = opts.port === void 0 ? void 0 : parsePorts([opts.port])[0];
|
|
4853
4929
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
@@ -4883,8 +4959,8 @@ kvbox checks every minute; ${domain} is served at ${d.url} once its records are
|
|
|
4883
4959
|
});
|
|
4884
4960
|
|
|
4885
4961
|
// src/commands/domain/ls.ts
|
|
4886
|
-
import { Command as
|
|
4887
|
-
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) => {
|
|
4888
4964
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4889
4965
|
try {
|
|
4890
4966
|
requireCloud5(client);
|
|
@@ -4913,8 +4989,8 @@ var lsCommand10 = new Command65("ls").alias("list").description("list your custo
|
|
|
4913
4989
|
});
|
|
4914
4990
|
|
|
4915
4991
|
// src/commands/domain/rm.ts
|
|
4916
|
-
import { Command as
|
|
4917
|
-
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) => {
|
|
4918
4994
|
const domain = domainArg.trim().toLowerCase();
|
|
4919
4995
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4920
4996
|
try {
|
|
@@ -4935,7 +5011,7 @@ var rmCommand9 = new Command66("rm").alias("remove").description("stop serving a
|
|
|
4935
5011
|
});
|
|
4936
5012
|
|
|
4937
5013
|
// src/commands/domain/index.ts
|
|
4938
|
-
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);
|
|
4939
5015
|
for (const cmd of domainCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
4940
5016
|
|
|
4941
5017
|
// src/commands/update.ts
|
|
@@ -4943,7 +5019,7 @@ import { spawn as spawn6 } from "child_process";
|
|
|
4943
5019
|
import { mkdtempSync, rmSync, writeFileSync as writeFileSync2 } from "fs";
|
|
4944
5020
|
import { tmpdir } from "os";
|
|
4945
5021
|
import { join as join8 } from "path";
|
|
4946
|
-
import { Command as
|
|
5022
|
+
import { Command as Command69 } from "commander";
|
|
4947
5023
|
|
|
4948
5024
|
// src/update.ts
|
|
4949
5025
|
import { mkdirSync, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
@@ -5062,7 +5138,7 @@ function run(cmd, args) {
|
|
|
5062
5138
|
child.on("exit", (code, signal) => resolve3(code ?? (signal ? 1 : 0)));
|
|
5063
5139
|
});
|
|
5064
5140
|
}
|
|
5065
|
-
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 () => {
|
|
5066
5142
|
suppressUpdateNotice();
|
|
5067
5143
|
const inst = installerFor(process.platform, process.env["KVBOX_INSTALL_URL"] || INSTALL_BASE);
|
|
5068
5144
|
let code;
|
|
@@ -5082,9 +5158,108 @@ var selfUpdateCommand = new Command68("update").description("update kvbox to the
|
|
|
5082
5158
|
if (code !== 0) throw new KvboxError(`the installer failed (exit ${code})`, code);
|
|
5083
5159
|
});
|
|
5084
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
|
+
|
|
5085
5260
|
// src/program.ts
|
|
5086
5261
|
function buildProgram() {
|
|
5087
|
-
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();
|
|
5088
5263
|
program.addCommand(vmCommand);
|
|
5089
5264
|
program.addCommand(snapshotsCommand);
|
|
5090
5265
|
program.addCommand(volumeCommand);
|
|
@@ -5096,9 +5271,11 @@ function buildProgram() {
|
|
|
5096
5271
|
program.addCommand(orgCommand);
|
|
5097
5272
|
program.addCommand(usageCommand2);
|
|
5098
5273
|
program.addCommand(creditCommand);
|
|
5274
|
+
program.addCommand(redeemCommand);
|
|
5099
5275
|
program.addCommand(deployCommand);
|
|
5100
5276
|
program.addCommand(selfUpdateCommand);
|
|
5101
5277
|
for (const cmd of vmAliases) program.addCommand(cmd);
|
|
5278
|
+
installRootHelp(program);
|
|
5102
5279
|
return program;
|
|
5103
5280
|
}
|
|
5104
5281
|
|