@kvbox/cli 0.6.9 → 0.6.10
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 +560 -230
- package/dist/kvbox.js.map +1 -1
- package/package.json +1 -1
package/dist/kvbox.js
CHANGED
|
@@ -155,7 +155,7 @@ async function spin(message, work, opts = {}) {
|
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
// src/program.ts
|
|
158
|
-
import { Command as
|
|
158
|
+
import { Command as Command129 } from "commander";
|
|
159
159
|
|
|
160
160
|
// ../shared/src/version.ts
|
|
161
161
|
import { createRequire } from "module";
|
|
@@ -170,7 +170,7 @@ function versionOf(srcFileUrl, injected) {
|
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
// src/version.ts
|
|
173
|
-
var VERSION = versionOf(import.meta.url, true ? "0.6.
|
|
173
|
+
var VERSION = versionOf(import.meta.url, true ? "0.6.10" : void 0);
|
|
174
174
|
|
|
175
175
|
// src/commands/vm/index.ts
|
|
176
176
|
import { Command as Command38 } from "commander";
|
|
@@ -240,6 +240,8 @@ function paths(home = kvboxHome()) {
|
|
|
240
240
|
},
|
|
241
241
|
assets: join(home, "assets"),
|
|
242
242
|
kernel: join(home, "assets", "vmlinux"),
|
|
243
|
+
/** A kernel an image asks for by name in its image.json (`"kernel": "android"`): assets/vmlinux-<name>, put there by install-server.sh. */
|
|
244
|
+
namedKernel: (name) => join(home, "assets", `vmlinux-${name}`),
|
|
243
245
|
/** Symlink to the current base image, assets/rootfs-<version>.ext4; boxes keep using the version they were made from. */
|
|
244
246
|
rootfs: join(home, "assets", "rootfs.ext4"),
|
|
245
247
|
baseImage: (version) => join(home, "assets", `rootfs-${version}.ext4`),
|
|
@@ -454,6 +456,12 @@ var BackupSchema = z.object({
|
|
|
454
456
|
createdAt: z.string(),
|
|
455
457
|
finishedAt: z.string().nullable()
|
|
456
458
|
});
|
|
459
|
+
var BackupLimitSchema = z.object({
|
|
460
|
+
perDay: z.number().int(),
|
|
461
|
+
used: z.number().int(),
|
|
462
|
+
nextAt: z.string().nullable()
|
|
463
|
+
});
|
|
464
|
+
var NamedBackupLimitSchema = BackupLimitSchema.extend({ owner: z.string(), name: z.string() });
|
|
457
465
|
var HostBackupRequest = z.object({ id: z.string(), key: z.string() });
|
|
458
466
|
var HostBackupManifestSchema = z.object({
|
|
459
467
|
id: z.string(),
|
|
@@ -496,6 +504,16 @@ var VolumeBackupSchema = z.object({
|
|
|
496
504
|
createdAt: z.string(),
|
|
497
505
|
finishedAt: z.string().nullable()
|
|
498
506
|
});
|
|
507
|
+
var BackupScheduleSchema = z.object({
|
|
508
|
+
enabled: z.boolean(),
|
|
509
|
+
/** 0-23, UTC. Kept while it is off, so turning it on again keeps the hour. */
|
|
510
|
+
hour: z.number().int().min(0).max(23),
|
|
511
|
+
nextAt: z.string().nullable(),
|
|
512
|
+
lastAt: z.string().nullable(),
|
|
513
|
+
lastBackup: z.string().nullable(),
|
|
514
|
+
lastError: z.string().nullable()
|
|
515
|
+
});
|
|
516
|
+
var SetBackupScheduleRequest = z.object({ enabled: z.boolean().optional(), hour: z.number().int().min(0).max(23).optional() });
|
|
499
517
|
var HostVolumeBackupManifestSchema = z.object({ id: z.string(), sizeBytes: z.number().int(), chunks: z.array(z.string().nullable()) });
|
|
500
518
|
var HostVolumeRestoreRequest = z.object({
|
|
501
519
|
id: z.string(),
|
|
@@ -1024,6 +1042,16 @@ var CronUsageSchema = z.object({
|
|
|
1024
1042
|
/** When it was made. */
|
|
1025
1043
|
historyFrom: z.string().nullable()
|
|
1026
1044
|
});
|
|
1045
|
+
var BackupUsageSchema = z.object({
|
|
1046
|
+
id: z.string(),
|
|
1047
|
+
kind: z.string(),
|
|
1048
|
+
name: z.string(),
|
|
1049
|
+
owner: z.string(),
|
|
1050
|
+
ownerKind: z.enum(["user", "org"]).optional(),
|
|
1051
|
+
/** How many paid backups turned ready in the window. */
|
|
1052
|
+
count: z.number().int(),
|
|
1053
|
+
cost: z.object({ amount: z.number(), currency: z.string() })
|
|
1054
|
+
});
|
|
1027
1055
|
var UsageDayItemSchema = z.object({
|
|
1028
1056
|
id: z.string(),
|
|
1029
1057
|
name: z.string(),
|
|
@@ -1044,7 +1072,9 @@ var UsageDaySchema = z.object({
|
|
|
1044
1072
|
/** Object storage that existed that day (#182); absent on a day without any. */
|
|
1045
1073
|
storage: z.array(UsageDayItemSchema).optional(),
|
|
1046
1074
|
/** Cron services that existed that day (#190); absent on a day without any. */
|
|
1047
|
-
cron: z.array(UsageDayItemSchema).optional()
|
|
1075
|
+
cron: z.array(UsageDayItemSchema).optional(),
|
|
1076
|
+
/** Paid backups that turned ready that day, summed per thing backed up (`id` is `<owner>/<kind>:<name>`); absent on a day without any. */
|
|
1077
|
+
backups: z.array(UsageDayItemSchema).optional()
|
|
1048
1078
|
});
|
|
1049
1079
|
var UsageReportSchema = z.object({
|
|
1050
1080
|
window: z.object({ from: z.string(), to: z.string() }),
|
|
@@ -1059,6 +1089,8 @@ var UsageReportSchema = z.object({
|
|
|
1059
1089
|
storage: z.array(VolumeUsageSchema).optional(),
|
|
1060
1090
|
/** Cron services (#190, control plane only): one row per service a slug has or had. Absent when there is none. */
|
|
1061
1091
|
cron: z.array(CronUsageSchema).optional(),
|
|
1092
|
+
/** Paid backups (control plane only): one row per box, volume or service backed up by hand in the window. Absent when there is none. */
|
|
1093
|
+
backups: z.array(BackupUsageSchema).optional(),
|
|
1062
1094
|
/** With `?by=day` only, oldest day first. */
|
|
1063
1095
|
days: z.array(UsageDaySchema).optional(),
|
|
1064
1096
|
totals: z.object({
|
|
@@ -1068,7 +1100,7 @@ var UsageReportSchema = z.object({
|
|
|
1068
1100
|
diskGibHours: z.number(),
|
|
1069
1101
|
volumeHours: z.number().optional(),
|
|
1070
1102
|
volumeGibHours: z.number().optional(),
|
|
1071
|
-
/** Boxes, volumes, object storage
|
|
1103
|
+
/** Boxes, volumes, object storage, cron services and paid backups together. */
|
|
1072
1104
|
cost: z.object({ amount: z.number(), currency: z.string() }).optional()
|
|
1073
1105
|
})
|
|
1074
1106
|
});
|
|
@@ -2051,9 +2083,6 @@ var Kvbox = class {
|
|
|
2051
2083
|
// src/client.ts
|
|
2052
2084
|
import { z as z11 } from "zod";
|
|
2053
2085
|
|
|
2054
|
-
// ../shared/src/managed.ts
|
|
2055
|
-
import { z as z8 } from "zod";
|
|
2056
|
-
|
|
2057
2086
|
// ../shared/src/usage.ts
|
|
2058
2087
|
import { z as z7 } from "zod";
|
|
2059
2088
|
var PricingSchema = z7.object({
|
|
@@ -2073,7 +2102,12 @@ var PricingSchema = z7.object({
|
|
|
2073
2102
|
storageGibHour: z7.number().nonnegative().default(0),
|
|
2074
2103
|
storageIncludedGib: z7.number().int().nonnegative().default(0),
|
|
2075
2104
|
/** The cron service (#190): an hour of one cron service existing, whatever it holds or fires. A price list from before it charges nothing. */
|
|
2076
|
-
cronHour: z7.number().nonnegative().default(0)
|
|
2105
|
+
cronHour: z7.number().nonnegative().default(0),
|
|
2106
|
+
/**
|
|
2107
|
+
* One backup a person starts, of anything, charged once it is ready (decision "A backup taken by hand
|
|
2108
|
+
* costs a flat price…"); a failed one and a scheduled one cost nothing. A price list from before it charges nothing.
|
|
2109
|
+
*/
|
|
2110
|
+
backup: z7.number().nonnegative().default(0)
|
|
2077
2111
|
});
|
|
2078
2112
|
var PriceListSchema = PricingSchema.extend({ welcomeCredit: z7.number().nonnegative() });
|
|
2079
2113
|
var HOUR_MS = 36e5;
|
|
@@ -2103,6 +2137,7 @@ function sumUsage(items, pricing) {
|
|
|
2103
2137
|
var DAY_MS = 24 * HOUR_MS;
|
|
2104
2138
|
|
|
2105
2139
|
// ../shared/src/managed.ts
|
|
2140
|
+
import { z as z8 } from "zod";
|
|
2106
2141
|
var PriceSchema = z8.object({ perMonth: z8.number(), storagePerMonth: z8.number(), currency: z8.string() });
|
|
2107
2142
|
var ManagedCatalogEntrySchema = z8.object({
|
|
2108
2143
|
/** The kind, as in `/managed/<kind>`: `postgres`. */
|
|
@@ -2137,7 +2172,13 @@ var CreateManagedRequest = z8.object({
|
|
|
2137
2172
|
password: z8.string().optional(),
|
|
2138
2173
|
storageGib: z8.number().int().optional(),
|
|
2139
2174
|
/** Place it on the host of this box, so the box can be linked to it. */
|
|
2140
|
-
near: z8.string().optional()
|
|
2175
|
+
near: z8.string().optional(),
|
|
2176
|
+
/**
|
|
2177
|
+
* A backup of a database of the same kind and major version, of the same account (#186): the new
|
|
2178
|
+
* service starts on its data, a removed service's included. Its settings (Postgres: database, user)
|
|
2179
|
+
* are the backup's; the password is the new one.
|
|
2180
|
+
*/
|
|
2181
|
+
fromBackup: z8.string().optional()
|
|
2141
2182
|
});
|
|
2142
2183
|
var ManagedHealthSchema = z8.object({
|
|
2143
2184
|
/** Its first start has finished: it has set itself up on its storage. */
|
|
@@ -2179,11 +2220,17 @@ var ManagedSchema = z8.object({
|
|
|
2179
2220
|
/** Connection strings with the password as `****`. */
|
|
2180
2221
|
urls: UrlsSchema,
|
|
2181
2222
|
price: PriceSchema,
|
|
2223
|
+
/** Its nightly backup (#186 slice 4): on from creation, `kvbox <kind> backup schedule` changes it. Null for a control plane from before schedules. */
|
|
2224
|
+
backupSchedule: BackupScheduleSchema.nullable().default(null),
|
|
2182
2225
|
/** Only in `GET /managed/<kind>/<name>` (asked live): null when it is not running or did not answer. */
|
|
2183
2226
|
health: ManagedHealthSchema.nullable().optional()
|
|
2184
2227
|
});
|
|
2185
2228
|
var ManagedSecretSchema = z8.object({ password: z8.string(), urls: UrlsSchema });
|
|
2186
|
-
var CreatedManagedSchema = ManagedSchema.extend({
|
|
2229
|
+
var CreatedManagedSchema = ManagedSchema.extend({
|
|
2230
|
+
secret: ManagedSecretSchema,
|
|
2231
|
+
/** The backup it was made from (`fromBackup`), when it was. */
|
|
2232
|
+
fromBackup: z8.string().optional()
|
|
2233
|
+
});
|
|
2187
2234
|
var ResetPasswordRequest = z8.object({ password: z8.string().optional() });
|
|
2188
2235
|
var SetPublicRequest = z8.object({ on: z8.boolean() });
|
|
2189
2236
|
var ManagedLinkRequest = z8.object({ box: z8.string() });
|
|
@@ -2203,7 +2250,10 @@ var ManagedBackupSchema = z8.object({
|
|
|
2203
2250
|
dataBytes: z8.number().int().nullable(),
|
|
2204
2251
|
/** What this backup added to storage (encrypted, compressed): the chunks no earlier backup had. */
|
|
2205
2252
|
uploadedBytes: z8.number().int().nullable(),
|
|
2253
|
+
/** Who asked for it; for a scheduled one, the database's creator. */
|
|
2206
2254
|
createdBy: z8.string().nullable(),
|
|
2255
|
+
/** Started by the database's backup schedule, not by a person: it does not count toward the daily limit. */
|
|
2256
|
+
scheduled: z8.boolean().default(false),
|
|
2207
2257
|
createdAt: z8.string(),
|
|
2208
2258
|
finishedAt: z8.string().nullable()
|
|
2209
2259
|
});
|
|
@@ -2368,6 +2418,34 @@ var BucketKeySchema = z10.object({
|
|
|
2368
2418
|
var CreateBucketKeyRequest = z10.object({ name: z10.string().optional(), readOnly: z10.boolean().optional() });
|
|
2369
2419
|
var CreatedBucketKeySchema = BucketKeySchema.extend({ secret: z10.string(), endpoint: z10.string().nullable(), region: z10.string() });
|
|
2370
2420
|
var GrowStorageRequest = z10.object({ sizeGib: z10.number().int() });
|
|
2421
|
+
var StorageBackupSchema = z10.object({
|
|
2422
|
+
id: z10.string(),
|
|
2423
|
+
owner: z10.string(),
|
|
2424
|
+
status: z10.enum(BACKUP_STATUSES),
|
|
2425
|
+
/** Why it failed; null otherwise. */
|
|
2426
|
+
error: z10.string().nullable(),
|
|
2427
|
+
/** The storage's volume when taken. */
|
|
2428
|
+
diskBytes: z10.number().int().nullable(),
|
|
2429
|
+
/** What it holds: the slots that are not all zeros. */
|
|
2430
|
+
dataBytes: z10.number().int().nullable(),
|
|
2431
|
+
/** What this backup added to the backup store (encrypted, compressed). */
|
|
2432
|
+
uploadedBytes: z10.number().int().nullable(),
|
|
2433
|
+
/** The buckets it holds, and how many access keys they had, as kvbox knew them when it was taken. */
|
|
2434
|
+
buckets: z10.array(z10.string()),
|
|
2435
|
+
keys: z10.number().int(),
|
|
2436
|
+
createdBy: z10.string().nullable(),
|
|
2437
|
+
createdAt: z10.string(),
|
|
2438
|
+
finishedAt: z10.string().nullable()
|
|
2439
|
+
});
|
|
2440
|
+
var RestoredKeySchema = z10.object({ bucket: z10.string(), id: z10.string(), name: z10.string() });
|
|
2441
|
+
var StorageRestoreSchema = z10.object({
|
|
2442
|
+
backup: z10.string(),
|
|
2443
|
+
storage: ObjectStorageSchema,
|
|
2444
|
+
buckets: z10.object({ kept: z10.array(z10.string()), returned: z10.array(z10.string()), removed: z10.array(z10.string()) }),
|
|
2445
|
+
keys: z10.object({ dropped: z10.array(RestoredKeySchema), revoked: z10.array(RestoredKeySchema) }),
|
|
2446
|
+
checked: z10.boolean(),
|
|
2447
|
+
warnings: z10.array(z10.string())
|
|
2448
|
+
});
|
|
2371
2449
|
var OBJECT_LIST_MAX = 1e3;
|
|
2372
2450
|
var SHARE_LINK_MAX_SEC = 7 * 24 * 3600;
|
|
2373
2451
|
var UPLOAD_URL_SEC = 12 * 3600;
|
|
@@ -2755,6 +2833,10 @@ var ServerClient = class {
|
|
|
2755
2833
|
balance(org) {
|
|
2756
2834
|
return this.call("GET", "/billing/balance", BalanceSchema, void 0, org);
|
|
2757
2835
|
}
|
|
2836
|
+
/** The control plane's price list (`GET /pricing`); a control plane only. */
|
|
2837
|
+
priceList() {
|
|
2838
|
+
return this.call("GET", "/pricing", PriceListSchema);
|
|
2839
|
+
}
|
|
2758
2840
|
/** Redeem a promo code (#163) for the caller's slug, or for `--org`'s org, which they own; a control plane only. */
|
|
2759
2841
|
redeem(code) {
|
|
2760
2842
|
return this.call("POST", "/billing/redeem", RedeemResponseSchema, { code });
|
|
@@ -2876,6 +2958,24 @@ var ServerClient = class {
|
|
|
2876
2958
|
growStorage(sizeGib) {
|
|
2877
2959
|
return this.call("POST", "/storage/grow", ObjectStorageSchema, { sizeGib });
|
|
2878
2960
|
}
|
|
2961
|
+
/** Backups of the slug's whole object storage (#186 slice 3), newest first. */
|
|
2962
|
+
storageBackups() {
|
|
2963
|
+
return this.call("GET", "/storage/backups", z11.array(StorageBackupSchema));
|
|
2964
|
+
}
|
|
2965
|
+
storageBackup(id) {
|
|
2966
|
+
return this.call("GET", `/storage/backups/${encodeURIComponent(id)}`, StorageBackupSchema);
|
|
2967
|
+
}
|
|
2968
|
+
/** Starts one; it runs in the background (`running`), `storageBackup` says how it ended. */
|
|
2969
|
+
createStorageBackup() {
|
|
2970
|
+
return this.call("POST", "/storage/backups", StorageBackupSchema);
|
|
2971
|
+
}
|
|
2972
|
+
/**
|
|
2973
|
+
* Every bucket and key goes back to the backup's; the storage restarts. Waits for the whole download
|
|
2974
|
+
* (the control plane gives its host 2 h) and for the storage to answer again, so 2 h 10 min.
|
|
2975
|
+
*/
|
|
2976
|
+
restoreStorageBackup(id) {
|
|
2977
|
+
return this.call("POST", `/storage/backups/${encodeURIComponent(id)}/restore`, StorageRestoreSchema, {}, void 0, 2 * 36e5 + 10 * 6e4);
|
|
2978
|
+
}
|
|
2879
2979
|
// ---- managed services (#173): the control plane's alone ----
|
|
2880
2980
|
managedPath(kind, name, rest = "") {
|
|
2881
2981
|
return `/managed/${encodeURIComponent(kind)}${name === void 0 ? "" : `/${encodeURIComponent(name)}`}${rest}`;
|
|
@@ -2887,8 +2987,9 @@ var ServerClient = class {
|
|
|
2887
2987
|
listManaged(kind, opts = {}) {
|
|
2888
2988
|
return this.call("GET", `${kind === void 0 ? "/managed" : this.managedPath(kind)}${allQuery(opts)}`, z11.array(ManagedSchema), void 0, opts.org);
|
|
2889
2989
|
}
|
|
2990
|
+
/** From a backup (`fromBackup`) it waits for the restore too: the control plane gives its host 2 h for the download. */
|
|
2890
2991
|
createManaged(kind, req) {
|
|
2891
|
-
return this.call("POST", this.managedPath(kind), CreatedManagedSchema, req);
|
|
2992
|
+
return this.call("POST", this.managedPath(kind), CreatedManagedSchema, req, void 0, req.fromBackup === void 0 ? void 0 : 2 * 36e5 + 10 * 6e4);
|
|
2892
2993
|
}
|
|
2893
2994
|
/** With `health`, asked of the service itself. */
|
|
2894
2995
|
getManaged(kind, name) {
|
|
@@ -2925,6 +3026,14 @@ var ServerClient = class {
|
|
|
2925
3026
|
managedBackup(kind, name, id) {
|
|
2926
3027
|
return this.call("GET", this.managedPath(kind, name, `/backups/${encodeURIComponent(id)}`), ManagedBackupSchema);
|
|
2927
3028
|
}
|
|
3029
|
+
/** When the service is backed up on its own (#186 slice 4): nightly from its creation. */
|
|
3030
|
+
managedBackupSchedule(kind, name) {
|
|
3031
|
+
return this.call("GET", this.managedPath(kind, name, "/backup-schedule"), BackupScheduleSchema);
|
|
3032
|
+
}
|
|
3033
|
+
/** On or off, or another hour (UTC, which turns it on). */
|
|
3034
|
+
setManagedBackupSchedule(kind, name, change) {
|
|
3035
|
+
return this.call("PUT", this.managedPath(kind, name, "/backup-schedule"), BackupScheduleSchema, change);
|
|
3036
|
+
}
|
|
2928
3037
|
/** Starts one; it runs in the background (`running`), `managedBackup` says how it ended. */
|
|
2929
3038
|
createManagedBackup(kind, name) {
|
|
2930
3039
|
return this.call("POST", this.managedPath(kind, name, "/backups"), ManagedBackupSchema);
|
|
@@ -4263,19 +4372,76 @@ var hookCommand = new Command21("hook").description("URLs that wake a box when c
|
|
|
4263
4372
|
for (const cmd of hookCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
4264
4373
|
|
|
4265
4374
|
// src/commands/vm/backup/index.ts
|
|
4266
|
-
import { Command as
|
|
4375
|
+
import { Command as Command27 } from "commander";
|
|
4267
4376
|
|
|
4268
4377
|
// src/commands/vm/backup/create.ts
|
|
4269
|
-
import { Command as
|
|
4378
|
+
import { Command as Command23 } from "commander";
|
|
4270
4379
|
|
|
4271
4380
|
// src/commands/vm/backup/shared.ts
|
|
4272
4381
|
import { setTimeout as sleep3 } from "timers/promises";
|
|
4382
|
+
|
|
4383
|
+
// src/commands/vm/usage.ts
|
|
4384
|
+
import { Command as Command22 } from "commander";
|
|
4385
|
+
var usageCommand = new Command22("usage").description("how long a box ran, slept and sat stopped, as vCPU-hours, RAM and disk GiB-hours (and cost, when the host prices them)").argument("<name>", "box name").option("--since <date>", "count from this date instead of the box's creation, e.g. 2026-10-01").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
4386
|
+
let since;
|
|
4387
|
+
if (opts.since !== void 0) {
|
|
4388
|
+
const t = Date.parse(opts.since);
|
|
4389
|
+
if (Number.isNaN(t)) throw new KvboxError(`--since ${opts.since}: not a date; write it like 2026-10-19 or 2026-10-19T08:00:00Z`);
|
|
4390
|
+
since = new Date(t).toISOString();
|
|
4391
|
+
}
|
|
4392
|
+
const client = await clientFor(cmd.optsWithGlobals());
|
|
4393
|
+
try {
|
|
4394
|
+
const u = await client.machineUsage(name, since);
|
|
4395
|
+
if (opts.json) json(u);
|
|
4396
|
+
else process.stdout.write(block(u));
|
|
4397
|
+
} finally {
|
|
4398
|
+
await client.close();
|
|
4399
|
+
}
|
|
4400
|
+
});
|
|
4401
|
+
var day = (iso) => iso.slice(0, 10);
|
|
4402
|
+
var SYMBOLS = { EUR: "\u20AC", USD: "$", GBP: "\xA3" };
|
|
4403
|
+
function money(amount, currency) {
|
|
4404
|
+
const sign = amount < 0 ? "-" : "";
|
|
4405
|
+
const n = Math.abs(amount).toFixed(2);
|
|
4406
|
+
const sym = SYMBOLS[currency.toUpperCase()];
|
|
4407
|
+
return sym === void 0 ? `${sign}${n} ${currency}` : `${sign}${sym}${n}`;
|
|
4408
|
+
}
|
|
4409
|
+
function block(u) {
|
|
4410
|
+
const estimated = u.estimatedStops === 0 ? "" : color.dim(` (${u.estimatedStops} stop time${u.estimatedStops === 1 ? "" : "s"} estimated)`);
|
|
4411
|
+
const rows2 = [
|
|
4412
|
+
["name", boxName(u.name)],
|
|
4413
|
+
["status", status(u.status)],
|
|
4414
|
+
["window", `${day(u.window.from)} to ${day(u.window.to)}`],
|
|
4415
|
+
["running", duration(u.seconds.running) + estimated],
|
|
4416
|
+
["standby", duration(u.seconds.standby)],
|
|
4417
|
+
["hibernated", duration(u.seconds.hibernated)],
|
|
4418
|
+
["stopped", duration(u.seconds.stopped)],
|
|
4419
|
+
["vcpu-h", hours(u.vcpuHours)],
|
|
4420
|
+
["ram GiB-h", hours(u.ramGibHours)],
|
|
4421
|
+
["disk GiB-h", hours(u.diskGibHours)]
|
|
4422
|
+
];
|
|
4423
|
+
if (u.cost !== void 0) rows2.push(["cost", `${money(u.cost.amount, u.cost.currency)} ${color.dim("(estimated)")}`]);
|
|
4424
|
+
if (u.historyFrom !== null && u.historyFrom > u.window.from) {
|
|
4425
|
+
rows2.push(["history", color.dim(`from ${u.historyFrom.slice(0, 16).replace("T", " ")} UTC; the box is older, but its time before that was not recorded`)]);
|
|
4426
|
+
}
|
|
4427
|
+
const w = Math.max(...rows2.map(([k]) => k.length));
|
|
4428
|
+
return rows2.map(([k, v]) => `${" ".repeat(w - k.length)}${k}: ${v}`).join("\n") + "\n";
|
|
4429
|
+
}
|
|
4430
|
+
|
|
4431
|
+
// src/commands/vm/backup/shared.ts
|
|
4273
4432
|
function requireCloud3(client) {
|
|
4274
4433
|
if (client.target.kind !== "cloud") throw new KvboxError("backups need the kvbox cloud: kvbox login (this host's own socket has none)");
|
|
4275
4434
|
}
|
|
4276
4435
|
var POLL_MS = 2e3;
|
|
4277
4436
|
var POLL_TRIES = 30;
|
|
4278
4437
|
var WAIT_MS = 7 * 36e5;
|
|
4438
|
+
async function printCost(client, done, nightly = false) {
|
|
4439
|
+
const prices = await client.priceList().catch(() => void 0);
|
|
4440
|
+
if (!prices || prices.backup <= 0) return;
|
|
4441
|
+
const price = money(prices.backup, prices.currency);
|
|
4442
|
+
const included = nightly ? "; the nightly backup is included" : "";
|
|
4443
|
+
info(color.dim(done ? ` cost: ${price}${included}` : ` costs ${price} once it is ready, nothing if it fails${included}`));
|
|
4444
|
+
}
|
|
4279
4445
|
async function untilSettled(ask, what, id, where, opts = {}) {
|
|
4280
4446
|
const { pollMs = POLL_MS, tries = POLL_TRIES, waitMs = WAIT_MS } = opts;
|
|
4281
4447
|
const lostTrack = (why) => new KvboxError(`stopped waiting for backup ${id} of ${what} (${why}); it may still be running: ${where}`);
|
|
@@ -4316,7 +4482,7 @@ async function removeListed(client, listed, nameOf, name, id, what, yes) {
|
|
|
4316
4482
|
}
|
|
4317
4483
|
|
|
4318
4484
|
// src/commands/vm/backup/create.ts
|
|
4319
|
-
var createCommand2 = new
|
|
4485
|
+
var createCommand2 = new Command23("create").description("back up a box's disk to the kvbox cloud (encrypted; memory and volumes not included)").argument("<box>", "box name").option("--wait", "stay until the backup is ready (by default it runs in the background)").option("--json", "print the backup as JSON").action(async (name, opts, cmd) => {
|
|
4320
4486
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
4321
4487
|
try {
|
|
4322
4488
|
requireCloud3(client);
|
|
@@ -4328,6 +4494,7 @@ var createCommand2 = new Command22("create").description("back up a box's disk t
|
|
|
4328
4494
|
else {
|
|
4329
4495
|
info(`${color.green("\u2713")} backup ${started.id} of box ${color.bold(box2)} started; it runs in the background`);
|
|
4330
4496
|
info(color.dim(` status: kvbox vm backup ls ${box2}`));
|
|
4497
|
+
await printCost(client, false);
|
|
4331
4498
|
}
|
|
4332
4499
|
return;
|
|
4333
4500
|
}
|
|
@@ -4338,14 +4505,15 @@ var createCommand2 = new Command22("create").description("back up a box's disk t
|
|
|
4338
4505
|
info(`${color.green("\u2713")} backup ${done.id} of box ${color.bold(box2)}: ${sizeLine(done)}`);
|
|
4339
4506
|
if ((found.volumes?.length ?? 0) > 0) info(color.dim(` not included: volume${found.volumes.length > 1 ? "s" : ""} ${found.volumes.map((v) => v.name).join(", ")}`));
|
|
4340
4507
|
info(color.dim(` restore with: kvbox vm backup restore ${box2} ${done.id}`));
|
|
4508
|
+
await printCost(client, true);
|
|
4341
4509
|
} finally {
|
|
4342
4510
|
await client.close();
|
|
4343
4511
|
}
|
|
4344
4512
|
});
|
|
4345
4513
|
|
|
4346
4514
|
// src/commands/vm/backup/ls.ts
|
|
4347
|
-
import { Command as
|
|
4348
|
-
var lsCommand4 = new
|
|
4515
|
+
import { Command as Command24 } from "commander";
|
|
4516
|
+
var lsCommand4 = new Command24("ls").alias("list").description("list backups: every box's, or one box's").argument("[box]", "box name (default: every box)").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
4349
4517
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
4350
4518
|
try {
|
|
4351
4519
|
requireCloud3(client);
|
|
@@ -4379,8 +4547,8 @@ var lsCommand4 = new Command23("ls").alias("list").description("list backups: ev
|
|
|
4379
4547
|
});
|
|
4380
4548
|
|
|
4381
4549
|
// src/commands/vm/backup/restore.ts
|
|
4382
|
-
import { Command as
|
|
4383
|
-
var restoreCommand = new
|
|
4550
|
+
import { Command as Command25 } from "commander";
|
|
4551
|
+
var restoreCommand = new Command25("restore").description("put a backup back: the box's disk becomes the backup's (a running box restarts)").argument("<box>", "box name").argument("<id>", "the backup's id (kvbox vm backup ls <box>)").option("-y, --yes", "do not ask for confirmation").option("--json", "print the box as JSON").action(async (name, id, opts, cmd) => {
|
|
4384
4552
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
4385
4553
|
try {
|
|
4386
4554
|
requireCloud3(client);
|
|
@@ -4404,8 +4572,8 @@ var restoreCommand = new Command24("restore").description("put a backup back: th
|
|
|
4404
4572
|
});
|
|
4405
4573
|
|
|
4406
4574
|
// src/commands/vm/backup/rm.ts
|
|
4407
|
-
import { Command as
|
|
4408
|
-
var rmCommand3 = new
|
|
4575
|
+
import { Command as Command26 } from "commander";
|
|
4576
|
+
var rmCommand3 = new Command26("rm").alias("remove").description("remove a backup for good (a box's that is gone too)").argument("<box>", "box name").argument("<id>", "the backup's id (kvbox vm backup ls <box>)").option("-y, --yes", "do not ask for confirmation").action(async (box2, id, opts, cmd) => {
|
|
4409
4577
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
4410
4578
|
try {
|
|
4411
4579
|
requireCloud3(client);
|
|
@@ -4416,12 +4584,12 @@ var rmCommand3 = new Command25("rm").alias("remove").description("remove a backu
|
|
|
4416
4584
|
});
|
|
4417
4585
|
|
|
4418
4586
|
// src/commands/vm/backup/index.ts
|
|
4419
|
-
var backupCommand = new
|
|
4587
|
+
var backupCommand = new Command27("backup").description("back up a box's disk to the kvbox cloud, list backups, restore or remove one").addCommand(createCommand2).addCommand(lsCommand4).addCommand(restoreCommand).addCommand(rmCommand3);
|
|
4420
4588
|
for (const cmd of backupCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
4421
4589
|
|
|
4422
4590
|
// src/commands/vm/rescale.ts
|
|
4423
|
-
import { Command as
|
|
4424
|
-
var rescaleCommand = new
|
|
4591
|
+
import { Command as Command28, Option as Option3 } from "commander";
|
|
4592
|
+
var rescaleCommand = new Command28("rescale").description("change a box's vCPUs, memory or disk (e.g. --vcpu 4 --mem 16GB); a running box restarts").argument("<name>", "box name").addOption(new Option3("-s, --size <size>", "a preset to start from").choices(SIZE_NAMES)).option("--vcpu <n>", "number of vCPUs").option("--mem <size>", "memory, e.g. 16GB or 4096MB").option("--disk <size>", "disk size, e.g. 32GB (grow only)").option("--force", "skip the capacity guard when a running box grows").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
4425
4593
|
const req = {
|
|
4426
4594
|
...opts.size !== void 0 ? { size: opts.size } : {},
|
|
4427
4595
|
...opts.vcpu !== void 0 ? { vcpu: parseCount(opts.vcpu) } : {},
|
|
@@ -4467,8 +4635,8 @@ function parseGib(flag, text2) {
|
|
|
4467
4635
|
}
|
|
4468
4636
|
|
|
4469
4637
|
// src/commands/vm/resume.ts
|
|
4470
|
-
import { Command as
|
|
4471
|
-
var resumeCommand = new
|
|
4638
|
+
import { Command as Command29 } from "commander";
|
|
4639
|
+
var resumeCommand = new Command29("resume").description("continue a box that is in standby (kvbox pause)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
4472
4640
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4473
4641
|
try {
|
|
4474
4642
|
const box2 = await spin(`resuming ${name}\u2026`, client.resumeMachine(name));
|
|
@@ -4480,8 +4648,8 @@ var resumeCommand = new Command28("resume").description("continue a box that is
|
|
|
4480
4648
|
});
|
|
4481
4649
|
|
|
4482
4650
|
// src/commands/vm/rm.ts
|
|
4483
|
-
import { Command as
|
|
4484
|
-
var rmCommand4 = new
|
|
4651
|
+
import { Command as Command30 } from "commander";
|
|
4652
|
+
var rmCommand4 = new Command30("rm").description("destroy a box (its disk is deleted; snapshots are kept)").argument("<name>", "box name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
|
|
4485
4653
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4486
4654
|
try {
|
|
4487
4655
|
const box2 = pickRef(await boxesFor(client, name), name, me(client));
|
|
@@ -4501,7 +4669,7 @@ var rmCommand4 = new Command29("rm").description("destroy a box (its disk is del
|
|
|
4501
4669
|
});
|
|
4502
4670
|
|
|
4503
4671
|
// src/commands/vm/set.ts
|
|
4504
|
-
import { Command as
|
|
4672
|
+
import { Command as Command31 } from "commander";
|
|
4505
4673
|
|
|
4506
4674
|
// src/swap.ts
|
|
4507
4675
|
import { spawn as spawn3 } from "child_process";
|
|
@@ -4577,7 +4745,7 @@ function runSwap(ep, mib) {
|
|
|
4577
4745
|
}
|
|
4578
4746
|
|
|
4579
4747
|
// src/commands/vm/set.ts
|
|
4580
|
-
var setCommand = new
|
|
4748
|
+
var setCommand = new Command31("set").description("change a box's settings, e.g. --auto-hibernate 30m (off: never), --idle-check /home/kvbox/idle.sh, --swap 2G").argument("<name>", "box name").option("--auto-hibernate <duration>", "hibernate the box after this long without network traffic (30m, 4h, 1d; off: never)").option("--idle-check <script>", "a script in the box that exits 0 when it is idle, asked instead of network traffic (off: none)").option("--swap <size>", "a swap file on the box's disk for memory spikes such as a build (2G, 512M; off: none)").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
4581
4749
|
if (opts.autoHibernate === void 0 && opts.idleCheck === void 0 && opts.swap === void 0) {
|
|
4582
4750
|
throw new KvboxError("nothing to change: give --auto-hibernate, --idle-check or --swap");
|
|
4583
4751
|
}
|
|
@@ -4646,8 +4814,8 @@ function parseIdleCheck(text2) {
|
|
|
4646
4814
|
}
|
|
4647
4815
|
|
|
4648
4816
|
// src/commands/vm/start.ts
|
|
4649
|
-
import { Command as
|
|
4650
|
-
var startCommand = new
|
|
4817
|
+
import { Command as Command32 } from "commander";
|
|
4818
|
+
var startCommand = new Command32("start").description("boot a stopped box again (same name, IP and disk)").argument("<name>", "box name").option("--force", "skip the capacity guard").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
4651
4819
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4652
4820
|
try {
|
|
4653
4821
|
const box2 = await spin(`booting ${name}\u2026`, client.startMachine(name, opts.force ?? false));
|
|
@@ -4659,8 +4827,8 @@ var startCommand = new Command31("start").description("boot a stopped box again
|
|
|
4659
4827
|
});
|
|
4660
4828
|
|
|
4661
4829
|
// src/commands/vm/stop.ts
|
|
4662
|
-
import { Command as
|
|
4663
|
-
var stopCommand = new
|
|
4830
|
+
import { Command as Command33 } from "commander";
|
|
4831
|
+
var stopCommand = new Command33("stop").description("shut a box down (its disk is kept; start it again with kvbox start)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
4664
4832
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4665
4833
|
try {
|
|
4666
4834
|
const box2 = await spin(`shutting ${name} down\u2026`, client.stopMachine(name));
|
|
@@ -4672,8 +4840,8 @@ var stopCommand = new Command32("stop").description("shut a box down (its disk i
|
|
|
4672
4840
|
});
|
|
4673
4841
|
|
|
4674
4842
|
// src/commands/vm/top.ts
|
|
4675
|
-
import { Command as
|
|
4676
|
-
var topCommand = new
|
|
4843
|
+
import { Command as Command34 } from "commander";
|
|
4844
|
+
var topCommand = new Command34("top").description("load, memory and disk of each running box, as the box itself sees them").option("-a, --all", "every running box on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
4677
4845
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4678
4846
|
try {
|
|
4679
4847
|
const running = (await client.listMachines({ all: opts.all })).filter((b) => b.status === "running");
|
|
@@ -4733,8 +4901,8 @@ function topRows(entries, cloud) {
|
|
|
4733
4901
|
}
|
|
4734
4902
|
|
|
4735
4903
|
// src/commands/vm/unlink.ts
|
|
4736
|
-
import { Command as
|
|
4737
|
-
var unlinkCommand = new
|
|
4904
|
+
import { Command as Command35 } from "commander";
|
|
4905
|
+
var unlinkCommand = new Command35("unlink").description("take a link away (kvbox vm link)").argument("<from>", "the box that connects").argument("<box>", "the box it reaches").requiredOption("-p, --port <port>", "the port in <box>").option("-y, --yes", "do not ask for confirmation").option("--json", "print the removed link as JSON").action(async (from, name, opts, cmd) => {
|
|
4738
4906
|
const port = parseLinkPort(opts.port);
|
|
4739
4907
|
if (!await confirm(`Cut box ${from} off from box ${name} port ${port}? Its open connections close too.`, opts.yes ?? false)) {
|
|
4740
4908
|
info("cancelled");
|
|
@@ -4755,8 +4923,8 @@ var unlinkCommand = new Command34("unlink").description("take a link away (kvbox
|
|
|
4755
4923
|
});
|
|
4756
4924
|
|
|
4757
4925
|
// src/commands/vm/update.ts
|
|
4758
|
-
import { Command as
|
|
4759
|
-
var updateCommand = new
|
|
4926
|
+
import { Command as Command36 } from "commander";
|
|
4927
|
+
var updateCommand = new Command36("update").description("move a box onto the current base image (its files stay; a running box restarts)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
4760
4928
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4761
4929
|
try {
|
|
4762
4930
|
const before = pickRef(await boxesFor(client, name), name, me(client));
|
|
@@ -4777,54 +4945,6 @@ var updateCommand = new Command35("update").description("move a box onto the cur
|
|
|
4777
4945
|
}
|
|
4778
4946
|
});
|
|
4779
4947
|
|
|
4780
|
-
// src/commands/vm/usage.ts
|
|
4781
|
-
import { Command as Command36 } from "commander";
|
|
4782
|
-
var usageCommand = new Command36("usage").description("how long a box ran, slept and sat stopped, as vCPU-hours, RAM and disk GiB-hours (and cost, when the host prices them)").argument("<name>", "box name").option("--since <date>", "count from this date instead of the box's creation, e.g. 2026-10-01").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
4783
|
-
let since;
|
|
4784
|
-
if (opts.since !== void 0) {
|
|
4785
|
-
const t = Date.parse(opts.since);
|
|
4786
|
-
if (Number.isNaN(t)) throw new KvboxError(`--since ${opts.since}: not a date; write it like 2026-10-19 or 2026-10-19T08:00:00Z`);
|
|
4787
|
-
since = new Date(t).toISOString();
|
|
4788
|
-
}
|
|
4789
|
-
const client = await clientFor(cmd.optsWithGlobals());
|
|
4790
|
-
try {
|
|
4791
|
-
const u = await client.machineUsage(name, since);
|
|
4792
|
-
if (opts.json) json(u);
|
|
4793
|
-
else process.stdout.write(block(u));
|
|
4794
|
-
} finally {
|
|
4795
|
-
await client.close();
|
|
4796
|
-
}
|
|
4797
|
-
});
|
|
4798
|
-
var day = (iso) => iso.slice(0, 10);
|
|
4799
|
-
var SYMBOLS = { EUR: "\u20AC", USD: "$", GBP: "\xA3" };
|
|
4800
|
-
function money(amount, currency) {
|
|
4801
|
-
const sign = amount < 0 ? "-" : "";
|
|
4802
|
-
const n = Math.abs(amount).toFixed(2);
|
|
4803
|
-
const sym = SYMBOLS[currency.toUpperCase()];
|
|
4804
|
-
return sym === void 0 ? `${sign}${n} ${currency}` : `${sign}${sym}${n}`;
|
|
4805
|
-
}
|
|
4806
|
-
function block(u) {
|
|
4807
|
-
const estimated = u.estimatedStops === 0 ? "" : color.dim(` (${u.estimatedStops} stop time${u.estimatedStops === 1 ? "" : "s"} estimated)`);
|
|
4808
|
-
const rows2 = [
|
|
4809
|
-
["name", boxName(u.name)],
|
|
4810
|
-
["status", status(u.status)],
|
|
4811
|
-
["window", `${day(u.window.from)} to ${day(u.window.to)}`],
|
|
4812
|
-
["running", duration(u.seconds.running) + estimated],
|
|
4813
|
-
["standby", duration(u.seconds.standby)],
|
|
4814
|
-
["hibernated", duration(u.seconds.hibernated)],
|
|
4815
|
-
["stopped", duration(u.seconds.stopped)],
|
|
4816
|
-
["vcpu-h", hours(u.vcpuHours)],
|
|
4817
|
-
["ram GiB-h", hours(u.ramGibHours)],
|
|
4818
|
-
["disk GiB-h", hours(u.diskGibHours)]
|
|
4819
|
-
];
|
|
4820
|
-
if (u.cost !== void 0) rows2.push(["cost", `${money(u.cost.amount, u.cost.currency)} ${color.dim("(estimated)")}`]);
|
|
4821
|
-
if (u.historyFrom !== null && u.historyFrom > u.window.from) {
|
|
4822
|
-
rows2.push(["history", color.dim(`from ${u.historyFrom.slice(0, 16).replace("T", " ")} UTC; the box is older, but its time before that was not recorded`)]);
|
|
4823
|
-
}
|
|
4824
|
-
const w = Math.max(...rows2.map(([k]) => k.length));
|
|
4825
|
-
return rows2.map(([k, v]) => `${" ".repeat(w - k.length)}${k}: ${v}`).join("\n") + "\n";
|
|
4826
|
-
}
|
|
4827
|
-
|
|
4828
4948
|
// src/commands/vm/wake.ts
|
|
4829
4949
|
import { Command as Command37 } from "commander";
|
|
4830
4950
|
var wakeCommand = new Command37("wake").description("continue a hibernated box where it left off (same name, IP and disk)").argument("<name>", "box name").option("--force", "skip the capacity guard").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
@@ -5390,7 +5510,8 @@ var usageCommand2 = new Command56("usage").description("what your boxes and volu
|
|
|
5390
5510
|
const volumes = report.volumes ?? [];
|
|
5391
5511
|
const storage = report.storage ?? [];
|
|
5392
5512
|
const cron = report.cron ?? [];
|
|
5393
|
-
|
|
5513
|
+
const backups = report.backups ?? [];
|
|
5514
|
+
if (report.boxes.length === 0 && volumes.length === 0 && storage.length === 0 && cron.length === 0 && backups.length === 0) info("no usage in this window");
|
|
5394
5515
|
else if (report.boxes.length > 0) table(perUser ? userRows(perUser) : usageRows(report, cloud));
|
|
5395
5516
|
if (volumes.length > 0) {
|
|
5396
5517
|
info(volumes.length === 1 ? "1 volume" : `${volumes.length} volumes`);
|
|
@@ -5404,8 +5525,13 @@ var usageCommand2 = new Command56("usage").description("what your boxes and volu
|
|
|
5404
5525
|
info(cron.length === 1 ? "1 cron service" : `${cron.length} cron services`);
|
|
5405
5526
|
table(cronRows(report, cloud));
|
|
5406
5527
|
}
|
|
5407
|
-
if (
|
|
5408
|
-
const
|
|
5528
|
+
if (backups.length > 0) {
|
|
5529
|
+
const taken = backups.reduce((n, b) => n + b.count, 0);
|
|
5530
|
+
info(taken === 1 ? "1 backup taken by hand" : `${taken} backups taken by hand`);
|
|
5531
|
+
table(backupRows(report, cloud));
|
|
5532
|
+
}
|
|
5533
|
+
if ((volumes.length > 0 || storage.length > 0 || cron.length > 0 || backups.length > 0) && report.totals.cost !== void 0) {
|
|
5534
|
+
const what = ["boxes", ...volumes.length > 0 ? ["volumes"] : [], ...storage.length > 0 ? ["object storage"] : [], ...cron.length > 0 ? ["cron services"] : [], ...backups.length > 0 ? ["backups"] : []];
|
|
5409
5535
|
info(`total: ${money(report.totals.cost.amount, report.totals.cost.currency)} ${color.dim(`(${what.slice(0, -1).join(", ")} and ${what.at(-1)}, estimated)`)}`);
|
|
5410
5536
|
}
|
|
5411
5537
|
if (cloud) {
|
|
@@ -5508,6 +5634,15 @@ function cronRows(report, cloud) {
|
|
|
5508
5634
|
...priced ? { cost: money(s.cost?.amount ?? 0, currency) } : {}
|
|
5509
5635
|
}));
|
|
5510
5636
|
}
|
|
5637
|
+
function backupRows(report, cloud) {
|
|
5638
|
+
return (report.backups ?? []).map((b) => ({
|
|
5639
|
+
name: b.kind === "storage" ? "object storage" : b.name,
|
|
5640
|
+
kind: b.kind,
|
|
5641
|
+
...cloud ? { owner: ownerCell2(b, cloud.me) } : {},
|
|
5642
|
+
backups: String(b.count),
|
|
5643
|
+
cost: money(b.cost.amount, b.cost.currency)
|
|
5644
|
+
}));
|
|
5645
|
+
}
|
|
5511
5646
|
function byUser(report) {
|
|
5512
5647
|
const groups = /* @__PURE__ */ new Map();
|
|
5513
5648
|
for (const b of report.boxes) {
|
|
@@ -5524,7 +5659,7 @@ function byUser(report) {
|
|
|
5524
5659
|
return u;
|
|
5525
5660
|
});
|
|
5526
5661
|
users.sort((a, b) => a.user === null ? 1 : b.user === null ? -1 : a.user.localeCompare(b.user));
|
|
5527
|
-
return { window: report.window, users, ...report.volumes === void 0 ? {} : { volumes: report.volumes }, ...report.storage === void 0 ? {} : { storage: report.storage }, ...report.cron === void 0 ? {} : { cron: report.cron }, totals: report.totals };
|
|
5662
|
+
return { window: report.window, users, ...report.volumes === void 0 ? {} : { volumes: report.volumes }, ...report.storage === void 0 ? {} : { storage: report.storage }, ...report.cron === void 0 ? {} : { cron: report.cron }, ...report.backups === void 0 ? {} : { backups: report.backups }, totals: report.totals };
|
|
5528
5663
|
}
|
|
5529
5664
|
function userRows(r) {
|
|
5530
5665
|
const priced = r.totals.cost !== void 0;
|
|
@@ -7064,6 +7199,7 @@ var createCommand4 = new Command61("create").description("back up a volume's dis
|
|
|
7064
7199
|
else {
|
|
7065
7200
|
info(`${color.green("\u2713")} backup ${started.id} of volume ${color.bold(volume2)} started; it runs in the background`);
|
|
7066
7201
|
info(color.dim(` status: kvbox volume backup ls ${volume2}`));
|
|
7202
|
+
await printCost(client, false);
|
|
7067
7203
|
}
|
|
7068
7204
|
return;
|
|
7069
7205
|
}
|
|
@@ -7073,6 +7209,7 @@ var createCommand4 = new Command61("create").description("back up a volume's dis
|
|
|
7073
7209
|
if (opts.json) return;
|
|
7074
7210
|
info(`${color.green("\u2713")} backup ${done.id} of volume ${color.bold(volume2)}: ${sizeLine(done)}`);
|
|
7075
7211
|
info(color.dim(` restore with: kvbox volume backup restore ${volume2} ${done.id}`));
|
|
7212
|
+
await printCost(client, true);
|
|
7076
7213
|
} finally {
|
|
7077
7214
|
await client.close();
|
|
7078
7215
|
}
|
|
@@ -7296,9 +7433,12 @@ for (const cmd of volumeCommand.commands) cmd.option("--org <slug>", "act in thi
|
|
|
7296
7433
|
volumeCommand.addCommand(backupCommand2);
|
|
7297
7434
|
|
|
7298
7435
|
// src/commands/bucket/index.ts
|
|
7299
|
-
import { Command as
|
|
7436
|
+
import { Command as Command86 } from "commander";
|
|
7300
7437
|
|
|
7301
|
-
// src/commands/bucket/
|
|
7438
|
+
// src/commands/bucket/backup/index.ts
|
|
7439
|
+
import { Command as Command76 } from "commander";
|
|
7440
|
+
|
|
7441
|
+
// src/commands/bucket/backup/create.ts
|
|
7302
7442
|
import { Command as Command72 } from "commander";
|
|
7303
7443
|
|
|
7304
7444
|
// src/commands/bucket/shared.ts
|
|
@@ -7324,8 +7464,124 @@ function printRows(rows2) {
|
|
|
7324
7464
|
`);
|
|
7325
7465
|
}
|
|
7326
7466
|
|
|
7467
|
+
// src/commands/bucket/backup/create.ts
|
|
7468
|
+
var createCommand6 = new Command72("create").description("back up your object storage (every bucket and key) to the kvbox cloud, encrypted").option("--wait", "stay until the backup is ready (by default it runs in the background)").option("--json", "print the backup as JSON").action(async (opts, cmd) => {
|
|
7469
|
+
const client = await bucketClient(cmd);
|
|
7470
|
+
const ls = "kvbox bucket backup ls";
|
|
7471
|
+
try {
|
|
7472
|
+
const started = await client.createStorageBackup();
|
|
7473
|
+
const what = `the object storage of ${started.owner}`;
|
|
7474
|
+
if (!opts.wait) {
|
|
7475
|
+
if (opts.json) json(started);
|
|
7476
|
+
else {
|
|
7477
|
+
info(`${color.green("\u2713")} backup ${started.id} of ${what} started (${started.buckets.length} ${started.buckets.length === 1 ? "bucket" : "buckets"}); it runs in the background`);
|
|
7478
|
+
info(color.dim(` status: ${ls}`));
|
|
7479
|
+
await printCost(client, false);
|
|
7480
|
+
}
|
|
7481
|
+
return;
|
|
7482
|
+
}
|
|
7483
|
+
const done = await spin(`backing up ${what}\u2026`, untilSettled(() => client.storageBackup(started.id), what, started.id, ls));
|
|
7484
|
+
if (opts.json) json(done);
|
|
7485
|
+
if (done.status === "failed") throw new KvboxError(`backup ${done.id} of ${what} failed: ${done.error ?? "no reason given"}`);
|
|
7486
|
+
if (opts.json) return;
|
|
7487
|
+
info(`${color.green("\u2713")} backup ${done.id} of ${what}: ${done.buckets.join(", ")}; ${sizeLine(done)}`);
|
|
7488
|
+
info(color.dim(` restore with: kvbox bucket backup restore ${done.id}`));
|
|
7489
|
+
await printCost(client, true);
|
|
7490
|
+
} finally {
|
|
7491
|
+
await client.close();
|
|
7492
|
+
}
|
|
7493
|
+
});
|
|
7494
|
+
|
|
7495
|
+
// src/commands/bucket/backup/ls.ts
|
|
7496
|
+
import { Command as Command73 } from "commander";
|
|
7497
|
+
var lsCommand11 = new Command73("ls").alias("list").description("list the backups of your object storage").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
7498
|
+
const client = await bucketClient(cmd);
|
|
7499
|
+
try {
|
|
7500
|
+
const list = await client.storageBackups();
|
|
7501
|
+
if (opts.json) {
|
|
7502
|
+
json(list);
|
|
7503
|
+
return;
|
|
7504
|
+
}
|
|
7505
|
+
if (list.length === 0) {
|
|
7506
|
+
info("no backups yet; make one with: kvbox bucket backup create");
|
|
7507
|
+
return;
|
|
7508
|
+
}
|
|
7509
|
+
const anyError = list.some((b) => b.error !== null);
|
|
7510
|
+
table(
|
|
7511
|
+
list.map((b) => ({
|
|
7512
|
+
id: b.id,
|
|
7513
|
+
status: b.status === "ready" ? color.green(b.status) : b.status === "failed" ? color.red(b.status) : color.yellow(b.status),
|
|
7514
|
+
buckets: b.buckets.join(","),
|
|
7515
|
+
keys: b.keys,
|
|
7516
|
+
data: b.dataBytes === null ? "-" : gbShort(b.dataBytes),
|
|
7517
|
+
uploaded: b.uploadedBytes === null ? "-" : gbShort(b.uploadedBytes),
|
|
7518
|
+
by: b.createdBy ?? "-",
|
|
7519
|
+
taken: age(b.createdAt),
|
|
7520
|
+
...anyError ? { error: b.error ?? "" } : {}
|
|
7521
|
+
}))
|
|
7522
|
+
);
|
|
7523
|
+
} finally {
|
|
7524
|
+
await client.close();
|
|
7525
|
+
}
|
|
7526
|
+
});
|
|
7527
|
+
|
|
7528
|
+
// src/commands/bucket/backup/restore.ts
|
|
7529
|
+
import { Command as Command74 } from "commander";
|
|
7530
|
+
var restoreCommand3 = new Command74("restore").description("put a backup back: every bucket and key becomes the backup's (the storage restarts)").argument("<id>", "the backup's id (kvbox bucket backup ls)").option("-y, --yes", "do not ask for confirmation").option("--json", "print what changed as JSON").action(async (id, opts, cmd) => {
|
|
7531
|
+
const client = await bucketClient(cmd);
|
|
7532
|
+
try {
|
|
7533
|
+
const backup = await client.storageBackup(id);
|
|
7534
|
+
const what = `the object storage of ${backup.owner}`;
|
|
7535
|
+
const question = `Restore ${what} from backup ${backup.id} (${age(backup.createdAt)} ago, ${sizeLine(backup)}; buckets ${backup.buckets.join(", ")})? Everything written since is lost: buckets made since are removed with their files, and access keys made since stop working. It restarts.`;
|
|
7536
|
+
if (!await confirm(question, opts.yes ?? false)) {
|
|
7537
|
+
info("cancelled");
|
|
7538
|
+
process.exitCode = 1;
|
|
7539
|
+
return;
|
|
7540
|
+
}
|
|
7541
|
+
const done = await spin(`restoring ${what} from ${backup.id}\u2026`, client.restoreStorageBackup(id));
|
|
7542
|
+
if (opts.json) {
|
|
7543
|
+
json(done);
|
|
7544
|
+
return;
|
|
7545
|
+
}
|
|
7546
|
+
info(`${color.green("\u2713")} ${what} restored from backup ${backup.id}`);
|
|
7547
|
+
const list = (names2) => names2.join(", ");
|
|
7548
|
+
if (done.buckets.kept.length > 0) info(` buckets as they were then: ${list(done.buckets.kept)}`);
|
|
7549
|
+
if (done.buckets.returned.length > 0) info(` buckets back (removed since; no keys, make new ones): ${list(done.buckets.returned)}`);
|
|
7550
|
+
if (done.buckets.removed.length > 0) warn(` buckets gone (made since): ${list(done.buckets.removed)}`);
|
|
7551
|
+
if (done.keys.dropped.length > 0) warn(` keys that no longer work (made since): ${list(done.keys.dropped.map((k) => `${k.id} (${k.bucket}/${k.name})`))}`);
|
|
7552
|
+
if (done.keys.revoked.length > 0) info(` keys removed since stay removed: ${list(done.keys.revoked.map((k) => k.id))}`);
|
|
7553
|
+
for (const w of done.warnings) warn(` ${w}`);
|
|
7554
|
+
} finally {
|
|
7555
|
+
await client.close();
|
|
7556
|
+
}
|
|
7557
|
+
});
|
|
7558
|
+
|
|
7559
|
+
// src/commands/bucket/backup/rm.ts
|
|
7560
|
+
import { Command as Command75 } from "commander";
|
|
7561
|
+
var rmCommand11 = new Command75("rm").alias("remove").description("remove a backup of your object storage for good").argument("<id>", "the backup's id (kvbox bucket backup ls)").option("-y, --yes", "do not ask for confirmation").action(async (id, opts, cmd) => {
|
|
7562
|
+
const client = await bucketClient(cmd);
|
|
7563
|
+
try {
|
|
7564
|
+
const backup = (await client.storageBackups()).find((b) => b.id === id);
|
|
7565
|
+
if (!backup) throw new NotFoundError(`backup ${id} of your object storage`);
|
|
7566
|
+
const question = `Remove backup ${backup.id} of the object storage of ${backup.owner} (${age(backup.createdAt)} ago, ${backup.status === "ready" ? sizeLine(backup) : backup.status})? It cannot be restored after this.`;
|
|
7567
|
+
if (!await confirm(question, opts.yes ?? false)) {
|
|
7568
|
+
info("cancelled");
|
|
7569
|
+
process.exitCode = 1;
|
|
7570
|
+
return;
|
|
7571
|
+
}
|
|
7572
|
+
await client.removeBackup(backup.id);
|
|
7573
|
+
info(`${color.green("\u2713")} backup ${backup.id} of the object storage of ${backup.owner} removed`);
|
|
7574
|
+
} finally {
|
|
7575
|
+
await client.close();
|
|
7576
|
+
}
|
|
7577
|
+
});
|
|
7578
|
+
|
|
7579
|
+
// src/commands/bucket/backup/index.ts
|
|
7580
|
+
var backupCommand3 = new Command76("backup").aliases(["backups"]).description("back up your object storage to the kvbox cloud, list backups, restore or remove one").addCommand(createCommand6).addCommand(lsCommand11).addCommand(restoreCommand3).addCommand(rmCommand11);
|
|
7581
|
+
|
|
7327
7582
|
// src/commands/bucket/create.ts
|
|
7328
|
-
|
|
7583
|
+
import { Command as Command77 } from "commander";
|
|
7584
|
+
var createCommand7 = new Command77("create").description("make a bucket (the first one also makes your object storage)").argument("<name>", "bucket name: 3-63 lowercase letters, digits and '-'").option("--size <GB>", "how much your object storage may hold, when this is your first bucket (default 10)").option("--region <region>", "the S3 region of your object storage (ro-west-1, de-center-1), when this is your first bucket").option("--near <box>", "put the object storage on the host of this box, when this is your first bucket").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
7329
7585
|
const sizeGib = opts.size === void 0 ? void 0 : parseGib2(opts.size);
|
|
7330
7586
|
const client = await bucketClient(cmd);
|
|
7331
7587
|
try {
|
|
@@ -7345,8 +7601,8 @@ var createCommand6 = new Command72("create").description("make a bucket (the fir
|
|
|
7345
7601
|
});
|
|
7346
7602
|
|
|
7347
7603
|
// src/commands/bucket/grow.ts
|
|
7348
|
-
import { Command as
|
|
7349
|
-
var growCommand2 = new
|
|
7604
|
+
import { Command as Command78 } from "commander";
|
|
7605
|
+
var growCommand2 = new Command78("grow").description("make your object storage larger (all your buckets share it; it restarts once)").argument("<GB>", "the new size in GB, larger than what it has").option("--json", "print the object storage as JSON").action(async (size, opts, cmd) => {
|
|
7350
7606
|
const sizeGib = parseGib2(size, "size");
|
|
7351
7607
|
const client = await bucketClient(cmd);
|
|
7352
7608
|
try {
|
|
@@ -7359,8 +7615,8 @@ var growCommand2 = new Command73("grow").description("make your object storage l
|
|
|
7359
7615
|
});
|
|
7360
7616
|
|
|
7361
7617
|
// src/commands/bucket/info.ts
|
|
7362
|
-
import { Command as
|
|
7363
|
-
var infoCommand = new
|
|
7618
|
+
import { Command as Command79 } from "commander";
|
|
7619
|
+
var infoCommand = new Command79("info").description("one bucket: its address, what it holds, how full your object storage is").argument("<name>", "bucket name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
7364
7620
|
const client = await bucketClient(cmd);
|
|
7365
7621
|
try {
|
|
7366
7622
|
const b = await client.getBucket(name);
|
|
@@ -7389,11 +7645,11 @@ with the AWS CLI: aws s3 ls s3://${b.name} --endpoint-url ${b.endpoint}`));
|
|
|
7389
7645
|
});
|
|
7390
7646
|
|
|
7391
7647
|
// src/commands/bucket/key/index.ts
|
|
7392
|
-
import { Command as
|
|
7648
|
+
import { Command as Command83 } from "commander";
|
|
7393
7649
|
|
|
7394
7650
|
// src/commands/bucket/key/create.ts
|
|
7395
|
-
import { Command as
|
|
7396
|
-
var
|
|
7651
|
+
import { Command as Command80 } from "commander";
|
|
7652
|
+
var createCommand8 = new Command80("create").description("make an access key for a bucket (the secret is shown once)").argument("<bucket>", "bucket name").option("--name <label>", "what to call the key, to tell it from the others").option("--read-only", "the key reads the bucket but cannot write to it").option("--json", "print as JSON").action(async (bucket, opts, cmd) => {
|
|
7397
7653
|
const client = await bucketClient(cmd);
|
|
7398
7654
|
try {
|
|
7399
7655
|
const key = await client.createBucketKey(bucket, { ...opts.name !== void 0 ? { name: opts.name } : {}, ...opts.readOnly ? { readOnly: true } : {} });
|
|
@@ -7416,8 +7672,8 @@ var createCommand7 = new Command75("create").description("make an access key for
|
|
|
7416
7672
|
});
|
|
7417
7673
|
|
|
7418
7674
|
// src/commands/bucket/key/ls.ts
|
|
7419
|
-
import { Command as
|
|
7420
|
-
var
|
|
7675
|
+
import { Command as Command81 } from "commander";
|
|
7676
|
+
var lsCommand12 = new Command81("ls").alias("list").description("list a bucket's access keys (never their secrets)").argument("<bucket>", "bucket name").option("--json", "print as JSON").action(async (bucket, opts, cmd) => {
|
|
7421
7677
|
const client = await bucketClient(cmd);
|
|
7422
7678
|
try {
|
|
7423
7679
|
const keys = await client.listBucketKeys(bucket);
|
|
@@ -7436,8 +7692,8 @@ var lsCommand11 = new Command76("ls").alias("list").description("list a bucket's
|
|
|
7436
7692
|
});
|
|
7437
7693
|
|
|
7438
7694
|
// src/commands/bucket/key/rm.ts
|
|
7439
|
-
import { Command as
|
|
7440
|
-
var
|
|
7695
|
+
import { Command as Command82 } from "commander";
|
|
7696
|
+
var rmCommand12 = new Command82("rm").alias("remove").description("delete an access key: whatever uses it stops reaching the bucket").argument("<bucket>", "bucket name").argument("<access-key>", "the access key id (kvbox bucket key ls)").option("-y, --yes", "do not ask for confirmation").action(async (bucket, id, opts, cmd) => {
|
|
7441
7697
|
const client = await bucketClient(cmd);
|
|
7442
7698
|
try {
|
|
7443
7699
|
if (!await confirm(`Delete key ${id} of bucket ${bucket}? Whatever uses it stops working.`, opts.yes ?? false)) {
|
|
@@ -7453,11 +7709,11 @@ var rmCommand11 = new Command77("rm").alias("remove").description("delete an acc
|
|
|
7453
7709
|
});
|
|
7454
7710
|
|
|
7455
7711
|
// src/commands/bucket/key/index.ts
|
|
7456
|
-
var keyCommand2 = new
|
|
7712
|
+
var keyCommand2 = new Command83("key").aliases(["keys"]).description("access keys of a bucket: what your app signs in with").addCommand(createCommand8).addCommand(lsCommand12).addCommand(rmCommand12);
|
|
7457
7713
|
|
|
7458
7714
|
// src/commands/bucket/ls.ts
|
|
7459
|
-
import { Command as
|
|
7460
|
-
var
|
|
7715
|
+
import { Command as Command84 } from "commander";
|
|
7716
|
+
var lsCommand13 = new Command84("ls").alias("list").description("list buckets, and the object storage they are in").option("-a, --all", "every bucket on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
7461
7717
|
const client = await bucketClient(cmd);
|
|
7462
7718
|
try {
|
|
7463
7719
|
const buckets = await client.listBuckets({ all: opts.all });
|
|
@@ -7487,8 +7743,8 @@ var lsCommand12 = new Command79("ls").alias("list").description("list buckets, a
|
|
|
7487
7743
|
});
|
|
7488
7744
|
|
|
7489
7745
|
// src/commands/bucket/rm.ts
|
|
7490
|
-
import { Command as
|
|
7491
|
-
var
|
|
7746
|
+
import { Command as Command85 } from "commander";
|
|
7747
|
+
var rmCommand13 = new Command85("rm").alias("remove").description("delete an empty bucket and its keys (the last one takes your object storage with it)").argument("<name>", "bucket name").option("--force", "your last bucket only: delete it with everything in it").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
|
|
7492
7748
|
const client = await bucketClient(cmd);
|
|
7493
7749
|
try {
|
|
7494
7750
|
const question = opts.force ? `Delete bucket ${name} with everything in it, and the object storage it is in?` : `Delete bucket ${name} and its keys?`;
|
|
@@ -7507,18 +7763,18 @@ var rmCommand12 = new Command80("rm").alias("remove").description("delete an emp
|
|
|
7507
7763
|
});
|
|
7508
7764
|
|
|
7509
7765
|
// src/commands/bucket/index.ts
|
|
7510
|
-
var bucketCommand = new
|
|
7766
|
+
var bucketCommand = new Command86("bucket").aliases(["buckets"]).description("object storage: S3 buckets for your files, and the access keys your apps use").addCommand(createCommand7).addCommand(lsCommand13).addCommand(infoCommand).addCommand(growCommand2).addCommand(rmCommand13).addCommand(keyCommand2).addCommand(backupCommand3);
|
|
7511
7767
|
var withOrg = (cmd) => cmd.option("--org <slug>", "act in this org (- for your personal buckets)");
|
|
7512
7768
|
for (const cmd of bucketCommand.commands) {
|
|
7513
|
-
if (cmd === keyCommand2) cmd.commands.forEach(withOrg);
|
|
7769
|
+
if (cmd === keyCommand2 || cmd === backupCommand3) cmd.commands.forEach(withOrg);
|
|
7514
7770
|
else withOrg(cmd);
|
|
7515
7771
|
}
|
|
7516
7772
|
|
|
7517
7773
|
// src/commands/cron/index.ts
|
|
7518
|
-
import { Command as
|
|
7774
|
+
import { Command as Command99 } from "commander";
|
|
7519
7775
|
|
|
7520
7776
|
// src/commands/cron/create.ts
|
|
7521
|
-
import { Command as
|
|
7777
|
+
import { Command as Command87 } from "commander";
|
|
7522
7778
|
|
|
7523
7779
|
// src/commands/cron/shared.ts
|
|
7524
7780
|
async function cronClient(cmd) {
|
|
@@ -7579,7 +7835,7 @@ function printRows2(rows2) {
|
|
|
7579
7835
|
var noTriggers = (service) => info(`cron service ${service} has no triggers yet; add one with: kvbox cron trigger add ${service} <box> "0 6 * * *" --port 3000 (or --run "<command>")`);
|
|
7580
7836
|
|
|
7581
7837
|
// src/commands/cron/create.ts
|
|
7582
|
-
var
|
|
7838
|
+
var createCommand9 = new Command87("create").description("make a cron service: a named set of triggers").argument("<name>", "what to call it (lowercase letters, digits and '-')").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
7583
7839
|
const client = await cronClient(cmd);
|
|
7584
7840
|
try {
|
|
7585
7841
|
const service = await client.createCronService(name);
|
|
@@ -7596,8 +7852,8 @@ var createCommand8 = new Command82("create").description("make a cron service: a
|
|
|
7596
7852
|
});
|
|
7597
7853
|
|
|
7598
7854
|
// src/commands/cron/info.ts
|
|
7599
|
-
import { Command as
|
|
7600
|
-
var infoCommand2 = new
|
|
7855
|
+
import { Command as Command88 } from "commander";
|
|
7856
|
+
var infoCommand2 = new Command88("info").alias("get").description("show a cron service and its triggers").argument("<name>", "cron service name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
7601
7857
|
const client = await cronClient(cmd);
|
|
7602
7858
|
try {
|
|
7603
7859
|
const service = await client.getCronService(name);
|
|
@@ -7621,8 +7877,8 @@ var infoCommand2 = new Command83("info").alias("get").description("show a cron s
|
|
|
7621
7877
|
});
|
|
7622
7878
|
|
|
7623
7879
|
// src/commands/cron/ls.ts
|
|
7624
|
-
import { Command as
|
|
7625
|
-
var
|
|
7880
|
+
import { Command as Command89 } from "commander";
|
|
7881
|
+
var lsCommand14 = new Command89("ls").alias("list").description("list cron services").option("-a, --all", "every cron service on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
7626
7882
|
const client = await cronClient(cmd);
|
|
7627
7883
|
try {
|
|
7628
7884
|
const services = await client.listCronServices({ all: opts.all });
|
|
@@ -7642,8 +7898,8 @@ var lsCommand13 = new Command84("ls").alias("list").description("list cron servi
|
|
|
7642
7898
|
});
|
|
7643
7899
|
|
|
7644
7900
|
// src/commands/cron/rm.ts
|
|
7645
|
-
import { Command as
|
|
7646
|
-
var
|
|
7901
|
+
import { Command as Command90 } from "commander";
|
|
7902
|
+
var rmCommand14 = new Command90("rm").alias("remove").description("delete a cron service, its triggers and their run history").argument("<name>", "cron service name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
|
|
7647
7903
|
const client = await cronClient(cmd);
|
|
7648
7904
|
try {
|
|
7649
7905
|
if (!await confirm(`Delete cron service ${name}? Its triggers stop firing and their run history is deleted.`, opts.yes ?? false)) {
|
|
@@ -7659,10 +7915,10 @@ var rmCommand13 = new Command85("rm").alias("remove").description("delete a cron
|
|
|
7659
7915
|
});
|
|
7660
7916
|
|
|
7661
7917
|
// src/commands/cron/trigger/index.ts
|
|
7662
|
-
import { Command as
|
|
7918
|
+
import { Command as Command98 } from "commander";
|
|
7663
7919
|
|
|
7664
7920
|
// src/commands/cron/trigger/add.ts
|
|
7665
|
-
import { Command as
|
|
7921
|
+
import { Command as Command91 } from "commander";
|
|
7666
7922
|
function portOf(value) {
|
|
7667
7923
|
const n = Number(value);
|
|
7668
7924
|
if (!Number.isInteger(n) || n < 1 || n > 65535) throw new KvboxError(`--port ${value}: a port is a number from 1 to 65535`);
|
|
@@ -7682,7 +7938,7 @@ function timeoutOf(value) {
|
|
|
7682
7938
|
if (sec > MAX_CRON_COMMAND_TIMEOUT_SEC) throw new KvboxError(`--timeout ${value}: a command may run for ${MAX_CRON_COMMAND_TIMEOUT_SEC / 60} minutes at most`);
|
|
7683
7939
|
return sec;
|
|
7684
7940
|
}
|
|
7685
|
-
var addCommand3 = new
|
|
7941
|
+
var addCommand3 = new Command91("add").description("add a trigger: on a schedule, call a port of a box or run a command in it").argument("<service>", "cron service name").argument("<box>", "the box it acts on").argument("<expr>", 'cron expression in quotes, five fields: "0 6 * * *" is every day at 06:00').option("--port <n>", "call this port, the one your app listens on in the box").option("--path <path>", "with --port: path and query to request (default: /)").option("--method <method>", `with --port: HTTP method, ${CRON_METHODS.join(" or ")} (default: POST)`).option("--run <command>", 'or run this command in the box, in quotes: "node ~/app/embed.js"').option("--timeout <duration>", `with --run: stop the command after this long (90s, 10m, 1h; default: ${DEFAULT_CRON_COMMAND_TIMEOUT_SEC / 60}m)`).option("--tz <zone>", "time zone the schedule is read in, like Europe/Bucharest", "UTC").option("--json", "print as JSON").action(async (service, box2, expr, opts, cmd) => {
|
|
7686
7942
|
let action;
|
|
7687
7943
|
if (opts.run !== void 0) {
|
|
7688
7944
|
if (opts.port !== void 0 || opts.path !== void 0 || opts.method !== void 0) throw new KvboxError("a trigger runs a command or calls a port: use --run, or --port with --path and --method, not both");
|
|
@@ -7709,8 +7965,8 @@ var addCommand3 = new Command86("add").description("add a trigger: on a schedule
|
|
|
7709
7965
|
});
|
|
7710
7966
|
|
|
7711
7967
|
// src/commands/cron/trigger/ls.ts
|
|
7712
|
-
import { Command as
|
|
7713
|
-
var
|
|
7968
|
+
import { Command as Command92 } from "commander";
|
|
7969
|
+
var lsCommand15 = new Command92("ls").alias("list").description("list a cron service's triggers").argument("<service>", "cron service name").option("--json", "print as JSON").action(async (service, opts, cmd) => {
|
|
7714
7970
|
const client = await cronClient(cmd);
|
|
7715
7971
|
try {
|
|
7716
7972
|
const triggers = await client.listCronTriggers(service);
|
|
@@ -7726,8 +7982,8 @@ var lsCommand14 = new Command87("ls").alias("list").description("list a cron ser
|
|
|
7726
7982
|
});
|
|
7727
7983
|
|
|
7728
7984
|
// src/commands/cron/trigger/pause.ts
|
|
7729
|
-
import { Command as
|
|
7730
|
-
var pauseCommand2 = new
|
|
7985
|
+
import { Command as Command93 } from "commander";
|
|
7986
|
+
var pauseCommand2 = new Command93("pause").description("stop a trigger from firing until it is resumed").argument("<service>", "cron service name").argument("<id>", "trigger id (kvbox cron trigger ls)").option("--json", "print as JSON").action(async (service, id, opts, cmd) => {
|
|
7731
7987
|
const client = await cronClient(cmd);
|
|
7732
7988
|
try {
|
|
7733
7989
|
const trigger = await client.setCronTriggerEnabled(service, id, false);
|
|
@@ -7742,8 +7998,8 @@ var pauseCommand2 = new Command88("pause").description("stop a trigger from firi
|
|
|
7742
7998
|
});
|
|
7743
7999
|
|
|
7744
8000
|
// src/commands/cron/trigger/resume.ts
|
|
7745
|
-
import { Command as
|
|
7746
|
-
var resumeCommand2 = new
|
|
8001
|
+
import { Command as Command94 } from "commander";
|
|
8002
|
+
var resumeCommand2 = new Command94("resume").description("let a paused trigger fire again").argument("<service>", "cron service name").argument("<id>", "trigger id (kvbox cron trigger ls)").option("--json", "print as JSON").action(async (service, id, opts, cmd) => {
|
|
7747
8003
|
const client = await cronClient(cmd);
|
|
7748
8004
|
try {
|
|
7749
8005
|
const trigger = await client.setCronTriggerEnabled(service, id, true);
|
|
@@ -7758,8 +8014,8 @@ var resumeCommand2 = new Command89("resume").description("let a paused trigger f
|
|
|
7758
8014
|
});
|
|
7759
8015
|
|
|
7760
8016
|
// src/commands/cron/trigger/rm.ts
|
|
7761
|
-
import { Command as
|
|
7762
|
-
var
|
|
8017
|
+
import { Command as Command95 } from "commander";
|
|
8018
|
+
var rmCommand15 = new Command95("rm").alias("remove").description("delete a trigger and its run history").argument("<service>", "cron service name").argument("<id>", "trigger id (kvbox cron trigger ls)").option("-y, --yes", "do not ask for confirmation").action(async (service, id, opts, cmd) => {
|
|
7763
8019
|
const client = await cronClient(cmd);
|
|
7764
8020
|
try {
|
|
7765
8021
|
if (!await confirm(`Delete trigger ${id} of cron service ${service}? Its run history is deleted too.`, opts.yes ?? false)) {
|
|
@@ -7775,8 +8031,8 @@ var rmCommand14 = new Command90("rm").alias("remove").description("delete a trig
|
|
|
7775
8031
|
});
|
|
7776
8032
|
|
|
7777
8033
|
// src/commands/cron/trigger/run.ts
|
|
7778
|
-
import { Command as
|
|
7779
|
-
var runCommand = new
|
|
8034
|
+
import { Command as Command96 } from "commander";
|
|
8035
|
+
var runCommand = new Command96("run").description("fire a trigger now, once, besides its schedule").argument("<service>", "cron service name").argument("<id>", "trigger id (kvbox cron trigger ls)").option("--json", "print as JSON").action(async (service, id, opts, cmd) => {
|
|
7780
8036
|
const client = await cronClient(cmd);
|
|
7781
8037
|
try {
|
|
7782
8038
|
const trigger = await client.runCronTrigger(service, id);
|
|
@@ -7792,13 +8048,13 @@ var runCommand = new Command91("run").description("fire a trigger now, once, bes
|
|
|
7792
8048
|
});
|
|
7793
8049
|
|
|
7794
8050
|
// src/commands/cron/trigger/runs.ts
|
|
7795
|
-
import { Command as
|
|
8051
|
+
import { Command as Command97 } from "commander";
|
|
7796
8052
|
function limitOf(value) {
|
|
7797
8053
|
const n = Number(value);
|
|
7798
8054
|
if (!Number.isInteger(n) || n < 1) throw new KvboxError(`-n ${value}: a number of runs, 1 or more`);
|
|
7799
8055
|
return n;
|
|
7800
8056
|
}
|
|
7801
|
-
var runsCommand = new
|
|
8057
|
+
var runsCommand = new Command97("runs").aliases(["logs"]).description("show how a trigger's last runs ended").argument("<service>", "cron service name").argument("<id>", "trigger id (kvbox cron trigger ls)").option("-n, --limit <count>", "how many runs to show", "20").option("--json", "print as JSON").action(async (service, id, opts, cmd) => {
|
|
7802
8058
|
const limit = limitOf(opts.limit);
|
|
7803
8059
|
const client = await cronClient(cmd);
|
|
7804
8060
|
try {
|
|
@@ -7828,10 +8084,10 @@ var runsCommand = new Command92("runs").aliases(["logs"]).description("show how
|
|
|
7828
8084
|
});
|
|
7829
8085
|
|
|
7830
8086
|
// src/commands/cron/trigger/index.ts
|
|
7831
|
-
var triggerCommand = new
|
|
8087
|
+
var triggerCommand = new Command98("trigger").aliases(["triggers"]).description("a cron service's triggers: a schedule and the request it sends to a box").addCommand(addCommand3).addCommand(lsCommand15).addCommand(runsCommand).addCommand(runCommand).addCommand(pauseCommand2).addCommand(resumeCommand2).addCommand(rmCommand15);
|
|
7832
8088
|
|
|
7833
8089
|
// src/commands/cron/index.ts
|
|
7834
|
-
var cronCommand = new
|
|
8090
|
+
var cronCommand = new Command99("cron").description("cron: call a box on a schedule, waking it first if it sleeps").addCommand(createCommand9).addCommand(lsCommand14).addCommand(infoCommand2).addCommand(rmCommand14).addCommand(triggerCommand);
|
|
7835
8091
|
var withOrg2 = (cmd) => cmd.option("--org <slug>", "act in this org (- for your personal cron services)");
|
|
7836
8092
|
for (const cmd of cronCommand.commands) {
|
|
7837
8093
|
if (cmd === triggerCommand) cmd.commands.forEach(withOrg2);
|
|
@@ -7839,13 +8095,13 @@ for (const cmd of cronCommand.commands) {
|
|
|
7839
8095
|
}
|
|
7840
8096
|
|
|
7841
8097
|
// src/commands/managed/kind.ts
|
|
7842
|
-
import { Command as
|
|
8098
|
+
import { Command as Command118 } from "commander";
|
|
7843
8099
|
|
|
7844
8100
|
// src/commands/managed/backup/index.ts
|
|
7845
|
-
import { Command as
|
|
8101
|
+
import { Command as Command106 } from "commander";
|
|
7846
8102
|
|
|
7847
8103
|
// src/commands/managed/backup/create.ts
|
|
7848
|
-
import { Command as
|
|
8104
|
+
import { Command as Command101 } from "commander";
|
|
7849
8105
|
|
|
7850
8106
|
// src/commands/managed/shared.ts
|
|
7851
8107
|
import "commander";
|
|
@@ -7900,10 +8156,25 @@ function infoRows(spec, m, user) {
|
|
|
7900
8156
|
rows2.push(...settingRows(spec, m.settings), ["password", color.dim(`kvbox ${spec.command} password ${name}`)]);
|
|
7901
8157
|
rows2.push(["private", `${m.urls.private} ${color.dim(m.links.length > 0 ? `(from ${m.links.join(", ")})` : `(no box is linked: kvbox ${spec.command} link ${name} <box>)`)}`]);
|
|
7902
8158
|
rows2.push(["public", m.urls.public ?? color.dim(`off (kvbox ${spec.command} public ${name} on)`)]);
|
|
8159
|
+
if (m.backupSchedule !== null) rows2.push(["backups", scheduleText2(spec, name, m.backupSchedule)]);
|
|
7903
8160
|
rows2.push(["cost", `${money(m.price.perMonth, m.price.currency)} a month while it runs, ${money(m.price.storagePerMonth, m.price.currency)} stopped ${color.dim("(estimated)")}`]);
|
|
7904
8161
|
rows2.push(["created", `${age(m.createdAt)}${m.createdBy ? ` by ${m.createdBy}` : ""}`]);
|
|
7905
8162
|
return rows2;
|
|
7906
8163
|
}
|
|
8164
|
+
function scheduleText2(spec, name, s, now = Date.now()) {
|
|
8165
|
+
const at = `${String(s.hour).padStart(2, "0")}:00 UTC`;
|
|
8166
|
+
if (!s.enabled) return color.dim(`not on their own (kvbox ${spec.command} backup schedule ${name} --on, at ${at})`);
|
|
8167
|
+
const nextMs = s.nextAt === null ? null : Date.parse(s.nextAt) - now;
|
|
8168
|
+
const next = s.nextAt === null || nextMs === null ? "" : nextMs > -6e4 ? `, next in ${inHours(nextMs)}` : `, ${color.yellow(`due since ${s.nextAt.slice(0, 16).replace("T", " ")} UTC, waiting for the backup job`)}`;
|
|
8169
|
+
const failed = s.lastError !== null ? color.yellow(` last one failed: ${s.lastError}`) : "";
|
|
8170
|
+
return `daily at ${at}${next}${failed}`;
|
|
8171
|
+
}
|
|
8172
|
+
function inHours(ms) {
|
|
8173
|
+
const min = Math.max(0, Math.round(ms / 6e4));
|
|
8174
|
+
if (min < 60) return `${min}m`;
|
|
8175
|
+
const h = Math.floor(min / 60);
|
|
8176
|
+
return h < 24 ? `${h}h ${min % 60}m` : `${Math.floor(h / 24)}d ${h % 24}h`;
|
|
8177
|
+
}
|
|
7907
8178
|
function printRows3(rows2) {
|
|
7908
8179
|
const width2 = Math.max(...rows2.map(([label]) => label.length));
|
|
7909
8180
|
for (const [label, value] of rows2) process.stdout.write(`${color.dim(label.padEnd(width2))} ${value}
|
|
@@ -7928,7 +8199,7 @@ function parseStorage(text2, flag) {
|
|
|
7928
8199
|
}
|
|
7929
8200
|
|
|
7930
8201
|
// src/commands/managed/backup/create.ts
|
|
7931
|
-
var
|
|
8202
|
+
var createCommand10 = (spec) => new Command101("create").description("back up a database to the kvbox cloud (encrypted)").argument("<db>", "its name").option("--wait", "stay until the backup is ready (by default it runs in the background)").option("--json", "print the backup as JSON").action(async (name, opts, cmd) => {
|
|
7932
8203
|
const client = await managedClient(cmd);
|
|
7933
8204
|
const ls = `kvbox ${spec.command} backup ls ${name}`;
|
|
7934
8205
|
try {
|
|
@@ -7938,6 +8209,7 @@ var createCommand9 = (spec) => new Command96("create").description("back up a da
|
|
|
7938
8209
|
else {
|
|
7939
8210
|
info(`${color.green("\u2713")} backup ${started.id} of database ${color.bold(name)} started; it runs in the background`);
|
|
7940
8211
|
info(color.dim(` status: ${ls}`));
|
|
8212
|
+
await printCost(client, false, true);
|
|
7941
8213
|
}
|
|
7942
8214
|
return;
|
|
7943
8215
|
}
|
|
@@ -7947,47 +8219,67 @@ var createCommand9 = (spec) => new Command96("create").description("back up a da
|
|
|
7947
8219
|
if (opts.json) return;
|
|
7948
8220
|
info(`${color.green("\u2713")} backup ${done.id} of database ${color.bold(name)}: ${sizeLine(done)}`);
|
|
7949
8221
|
info(color.dim(` restore with: kvbox ${spec.command} backup restore ${name} ${done.id}`));
|
|
8222
|
+
await printCost(client, true, true);
|
|
7950
8223
|
} finally {
|
|
7951
8224
|
await client.close();
|
|
7952
8225
|
}
|
|
7953
8226
|
});
|
|
7954
8227
|
|
|
7955
8228
|
// src/commands/managed/backup/ls.ts
|
|
7956
|
-
import { Command as
|
|
7957
|
-
var
|
|
7958
|
-
const
|
|
7959
|
-
|
|
7960
|
-
const
|
|
7961
|
-
if (
|
|
7962
|
-
|
|
7963
|
-
|
|
7964
|
-
|
|
7965
|
-
|
|
7966
|
-
|
|
7967
|
-
|
|
8229
|
+
import { Command as Command102 } from "commander";
|
|
8230
|
+
var lsCommand16 = (spec) => {
|
|
8231
|
+
const removedOnes = async (err, name, client) => {
|
|
8232
|
+
if (!(err instanceof CallError && err.status === 404)) throw err;
|
|
8233
|
+
const gone = (await client.listManagedBackups(spec.kind)).filter((b) => b.name === name || `${b.owner}/${b.name}` === name);
|
|
8234
|
+
if (gone.length === 0) throw err;
|
|
8235
|
+
const own = name.includes("/") ? [] : gone.filter((b) => b.owner === me(client));
|
|
8236
|
+
return own.length > 0 ? own : gone;
|
|
8237
|
+
};
|
|
8238
|
+
return new Command102("ls").alias("list").description("list backups: every database's, or one database's").argument("[db]", "its name (default: every database)").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
8239
|
+
const client = await managedClient(cmd);
|
|
8240
|
+
try {
|
|
8241
|
+
const list = name === void 0 ? await client.listManagedBackups(spec.kind) : await client.managedBackups(spec.kind, name).catch((err) => removedOnes(err, name, client));
|
|
8242
|
+
if (opts.json) {
|
|
8243
|
+
json(list);
|
|
8244
|
+
return;
|
|
8245
|
+
}
|
|
8246
|
+
const schedule = name === void 0 ? null : await client.managedBackupSchedule(spec.kind, name).catch(() => null);
|
|
8247
|
+
const footer = () => {
|
|
8248
|
+
if (schedule !== null) info(`${color.dim("on its own:")} ${scheduleText2(spec, name, schedule)}`);
|
|
8249
|
+
};
|
|
8250
|
+
if (list.length === 0) {
|
|
8251
|
+
info(name === void 0 ? `no backups yet; make one with: kvbox ${spec.command} backup create <db>` : `database ${name} has no backups; make one with: kvbox ${spec.command} backup create ${name}`);
|
|
8252
|
+
footer();
|
|
8253
|
+
return;
|
|
8254
|
+
}
|
|
8255
|
+
const anyError = list.some((b) => b.error !== null);
|
|
8256
|
+
const others = [...new Set(list.filter((b) => b.owner !== me(client)).map((b) => b.owner))];
|
|
8257
|
+
table(
|
|
8258
|
+
list.map((b) => ({
|
|
8259
|
+
id: b.id,
|
|
8260
|
+
...name === void 0 || others.length > 0 ? { database: b.owner === me(client) ? b.name : `${b.owner}/${b.name}` } : {},
|
|
8261
|
+
status: b.status === "ready" ? color.green(b.status) : b.status === "failed" ? color.red(b.status) : color.yellow(b.status),
|
|
8262
|
+
version: b.version,
|
|
8263
|
+
data: b.dataBytes === null ? "-" : gbShort(b.dataBytes),
|
|
8264
|
+
uploaded: b.uploadedBytes === null ? "-" : gbShort(b.uploadedBytes),
|
|
8265
|
+
by: b.scheduled ? color.dim("schedule") : b.createdBy ?? "-",
|
|
8266
|
+
taken: age(b.createdAt),
|
|
8267
|
+
...anyError ? { error: b.error ?? "" } : {}
|
|
8268
|
+
}))
|
|
8269
|
+
);
|
|
8270
|
+
footer();
|
|
8271
|
+
if (name !== void 0 && others.length > 0) {
|
|
8272
|
+
info(color.dim(`A backup of ${others.join(", ")} makes a database there: kvbox ${spec.command} create <name> --from-backup <id> --org ${others[0]}`));
|
|
8273
|
+
}
|
|
8274
|
+
} finally {
|
|
8275
|
+
await client.close();
|
|
7968
8276
|
}
|
|
7969
|
-
|
|
7970
|
-
|
|
7971
|
-
list.map((b) => ({
|
|
7972
|
-
id: b.id,
|
|
7973
|
-
...name === void 0 ? { database: b.owner === me(client) ? b.name : `${b.owner}/${b.name}` } : {},
|
|
7974
|
-
status: b.status === "ready" ? color.green(b.status) : b.status === "failed" ? color.red(b.status) : color.yellow(b.status),
|
|
7975
|
-
version: b.version,
|
|
7976
|
-
data: b.dataBytes === null ? "-" : gbShort(b.dataBytes),
|
|
7977
|
-
uploaded: b.uploadedBytes === null ? "-" : gbShort(b.uploadedBytes),
|
|
7978
|
-
by: b.createdBy ?? "-",
|
|
7979
|
-
taken: age(b.createdAt),
|
|
7980
|
-
...anyError ? { error: b.error ?? "" } : {}
|
|
7981
|
-
}))
|
|
7982
|
-
);
|
|
7983
|
-
} finally {
|
|
7984
|
-
await client.close();
|
|
7985
|
-
}
|
|
7986
|
-
});
|
|
8277
|
+
});
|
|
8278
|
+
};
|
|
7987
8279
|
|
|
7988
8280
|
// src/commands/managed/backup/restore.ts
|
|
7989
|
-
import { Command as
|
|
7990
|
-
var
|
|
8281
|
+
import { Command as Command103 } from "commander";
|
|
8282
|
+
var restoreCommand4 = (spec) => new Command103("restore").description("put a backup back: the database's data becomes the backup's (it restarts)").argument("<db>", "its name").argument("<id>", `the backup's id (kvbox ${spec.command} backup ls <db>)`).option("-y, --yes", "do not ask for confirmation").option("--json", "print the database as JSON").action(async (name, id, opts, cmd) => {
|
|
7991
8283
|
const client = await managedClient(cmd);
|
|
7992
8284
|
try {
|
|
7993
8285
|
const backup = await client.managedBackup(spec.kind, name, id);
|
|
@@ -8009,8 +8301,8 @@ var restoreCommand3 = (spec) => new Command98("restore").description("put a back
|
|
|
8009
8301
|
});
|
|
8010
8302
|
|
|
8011
8303
|
// src/commands/managed/backup/rm.ts
|
|
8012
|
-
import { Command as
|
|
8013
|
-
var
|
|
8304
|
+
import { Command as Command104 } from "commander";
|
|
8305
|
+
var rmCommand16 = (spec) => new Command104("rm").alias("remove").description("remove a backup for good (a database's that is gone too)").argument("<db>", "its name").argument("<id>", `the backup's id (kvbox ${spec.command} backup ls <db>)`).option("-y, --yes", "do not ask for confirmation").action(async (name, id, opts, cmd) => {
|
|
8014
8306
|
const client = await managedClient(cmd);
|
|
8015
8307
|
try {
|
|
8016
8308
|
await removeListed(client, await client.listManagedBackups(spec.kind), (b) => b.name, name, id, `database ${name}`, opts.yes ?? false);
|
|
@@ -8019,34 +8311,71 @@ var rmCommand15 = (spec) => new Command99("rm").alias("remove").description("rem
|
|
|
8019
8311
|
}
|
|
8020
8312
|
});
|
|
8021
8313
|
|
|
8314
|
+
// src/commands/managed/backup/schedule.ts
|
|
8315
|
+
import { Command as Command105 } from "commander";
|
|
8316
|
+
var scheduleCommand = (spec) => new Command105("schedule").description("show or change when a database is backed up on its own (daily, UTC)").argument("<db>", "its name").option("--at <hour>", "back it up daily at this hour, 0-23 UTC (turns it on)").option("--off", "stop backing it up on its own").option("--on", "back it up on its own again, at the hour it had").option("--json", "print the schedule as JSON").action(async (name, opts, cmd) => {
|
|
8317
|
+
if (opts.off && (opts.on || opts.at !== void 0)) throw new KvboxError("--off takes neither --on nor --at");
|
|
8318
|
+
const hour = opts.at === void 0 ? void 0 : parseHour(opts.at);
|
|
8319
|
+
const client = await managedClient(cmd);
|
|
8320
|
+
try {
|
|
8321
|
+
const change = { ...opts.off ? { enabled: false } : opts.on ? { enabled: true } : {}, ...hour !== void 0 ? { hour } : {} };
|
|
8322
|
+
const changed = Object.keys(change).length > 0;
|
|
8323
|
+
const schedule = changed ? await client.setManagedBackupSchedule(spec.kind, name, change) : await client.managedBackupSchedule(spec.kind, name);
|
|
8324
|
+
if (opts.json) {
|
|
8325
|
+
json(schedule);
|
|
8326
|
+
return;
|
|
8327
|
+
}
|
|
8328
|
+
info(`${changed ? `${color.green("\u2713")} ` : ""}database ${color.bold(name)}: ${scheduleText2(spec, name, schedule)}`);
|
|
8329
|
+
if (schedule.lastAt !== null) {
|
|
8330
|
+
const last = schedule.lastError !== null ? color.red(`failed: ${schedule.lastError}`) : schedule.lastBackup !== null ? `backup ${schedule.lastBackup}` : "starting a backup";
|
|
8331
|
+
info(color.dim(` last turn ${schedule.lastAt.slice(0, 16).replace("T", " ")} UTC: `) + last);
|
|
8332
|
+
}
|
|
8333
|
+
} finally {
|
|
8334
|
+
await client.close();
|
|
8335
|
+
}
|
|
8336
|
+
});
|
|
8337
|
+
function parseHour(text2) {
|
|
8338
|
+
const m = /^(\d{1,2})(?::00)?$/.exec(text2.trim());
|
|
8339
|
+
const hour = m ? Number(m[1]) : NaN;
|
|
8340
|
+
if (!Number.isInteger(hour) || hour < 0 || hour > 23) throw new KvboxError(`--at ${text2}: an hour of the day, 0-23 (UTC), like 3 or 03:00`);
|
|
8341
|
+
return hour;
|
|
8342
|
+
}
|
|
8343
|
+
|
|
8022
8344
|
// src/commands/managed/backup/index.ts
|
|
8023
|
-
var
|
|
8024
|
-
const command = new
|
|
8025
|
-
for (const make of [
|
|
8345
|
+
var backupCommand4 = (spec) => {
|
|
8346
|
+
const command = new Command106("backup").description("back up a database to the kvbox cloud, list backups, restore or remove one, or change its nightly schedule");
|
|
8347
|
+
for (const make of [createCommand10, lsCommand16, restoreCommand4, rmCommand16, scheduleCommand]) command.addCommand(make(spec).option("--org <slug>", "act in this org (- for your personal databases)"));
|
|
8026
8348
|
return command;
|
|
8027
8349
|
};
|
|
8028
8350
|
|
|
8029
8351
|
// src/commands/managed/create.ts
|
|
8030
|
-
import { Command as
|
|
8352
|
+
import { Command as Command107 } from "commander";
|
|
8031
8353
|
import { setTimeout as sleep5 } from "timers/promises";
|
|
8032
8354
|
var READY_WAIT_MS = 9e4;
|
|
8033
8355
|
var READY_STEP_MS = 2e3;
|
|
8034
|
-
var
|
|
8035
|
-
const command = new
|
|
8356
|
+
var createCommand11 = (spec) => {
|
|
8357
|
+
const command = new Command107("create").alias("new").description(`create a ${spec.title} database: a name is all it needs`).argument("<name>", "its name (1-12 chars, lowercase letters, digits and '-'); a linked box reaches it at <name>.<account>.kvbox");
|
|
8036
8358
|
for (const o of spec.options) command.option(`--${o.name} <${o.arg}>`, o.help);
|
|
8037
|
-
return command.option("--password <password>", "its password (default: generated)").option("--storage <gb>", `storage for the data in GB (default: ${spec.storageGib}; it can grow later)`).option("--near <box>", "run it on the host of this box, so the box can be linked to it").option("--json", "print it as JSON, password included").action(async (name, opts, cmd) => {
|
|
8359
|
+
return command.option("--password <password>", "its password (default: generated)").option("--storage <gb>", `storage for the data in GB (default: ${spec.storageGib}; it can grow later)`).option("--near <box>", "run it on the host of this box, so the box can be linked to it").option("--from-backup <id>", `start it on this backup's data, a removed database's too (kvbox ${spec.command} backup ls)`).option("--json", "print it as JSON, password included").action(async (name, opts, cmd) => {
|
|
8038
8360
|
const options = Object.fromEntries(spec.options.flatMap((o) => typeof opts[o.name] === "string" ? [[o.name, opts[o.name]]] : []));
|
|
8039
8361
|
const req = {
|
|
8040
8362
|
name,
|
|
8041
8363
|
...Object.keys(options).length > 0 ? { options } : {},
|
|
8042
8364
|
...opts.password !== void 0 ? { password: opts.password } : {},
|
|
8043
8365
|
...opts.storage !== void 0 ? { storageGib: parseStorage(opts.storage, "--storage") } : {},
|
|
8044
|
-
...opts.near !== void 0 ? { near: opts.near } : {}
|
|
8366
|
+
...opts.near !== void 0 ? { near: opts.near } : {},
|
|
8367
|
+
...opts.fromBackup !== void 0 ? { fromBackup: opts.fromBackup } : {}
|
|
8045
8368
|
};
|
|
8046
8369
|
const client = await managedClient(cmd);
|
|
8047
8370
|
try {
|
|
8048
|
-
const
|
|
8371
|
+
const doing = opts.fromBackup === void 0 ? `creating ${spec.title} database ${name}\u2026` : `creating ${spec.title} database ${name} from backup ${opts.fromBackup}\u2026`;
|
|
8372
|
+
const made = await spin(doing, client.createManaged(spec.kind, req));
|
|
8049
8373
|
const shown = shownName3(made, me(client));
|
|
8374
|
+
if (opts.fromBackup !== void 0 && made.fromBackup === void 0) {
|
|
8375
|
+
throw new KvboxError(
|
|
8376
|
+
`this control plane does not know --from-backup yet: database ${shown} was made empty, not from backup ${opts.fromBackup}; remove it with: kvbox ${spec.command} rm ${shown}`
|
|
8377
|
+
);
|
|
8378
|
+
}
|
|
8050
8379
|
const ready = await spin(`starting ${spec.title}\u2026`, async () => {
|
|
8051
8380
|
for (const until2 = Date.now() + READY_WAIT_MS; Date.now() < until2; await sleep5(READY_STEP_MS)) {
|
|
8052
8381
|
const now = await client.getManaged(spec.kind, shown).catch(() => void 0);
|
|
@@ -8058,7 +8387,8 @@ var createCommand10 = (spec) => {
|
|
|
8058
8387
|
json({ ...made, ready });
|
|
8059
8388
|
return;
|
|
8060
8389
|
}
|
|
8061
|
-
|
|
8390
|
+
const restored = made.fromBackup === void 0 ? "" : `, the data of backup ${made.fromBackup}`;
|
|
8391
|
+
info(`${color.green("\u2713")} database ${color.bold(shown)} ${ready ? "is ready" : "is created and still starting"} ${color.dim(`(${spec.title} ${made.version}, ${made.storageGib} GB of storage${restored})`)}`);
|
|
8062
8392
|
printRows3([...settingRows(spec, made.settings), ...secretRows(made.secret)].map(([label, value]) => [` ${label}`, value]));
|
|
8063
8393
|
info("");
|
|
8064
8394
|
info("Nobody can reach it yet. To let something in:");
|
|
@@ -8073,8 +8403,8 @@ var createCommand10 = (spec) => {
|
|
|
8073
8403
|
};
|
|
8074
8404
|
|
|
8075
8405
|
// src/commands/managed/grow.ts
|
|
8076
|
-
import { Command as
|
|
8077
|
-
var growCommand3 = (spec) => new
|
|
8406
|
+
import { Command as Command108 } from "commander";
|
|
8407
|
+
var growCommand3 = (spec) => new Command108("grow").description("give a database more storage (it restarts once)").argument("<db>", "its name").argument("<GB>", "the new size in GB, larger than what it has").option("--json", "print as JSON").action(async (name, size, opts, cmd) => {
|
|
8078
8408
|
const storageGib = parseStorage(size, "size");
|
|
8079
8409
|
const client = await managedClient(cmd);
|
|
8080
8410
|
try {
|
|
@@ -8087,8 +8417,8 @@ var growCommand3 = (spec) => new Command102("grow").description("give a database
|
|
|
8087
8417
|
});
|
|
8088
8418
|
|
|
8089
8419
|
// src/commands/managed/info.ts
|
|
8090
|
-
import { Command as
|
|
8091
|
-
var infoCommand3 = (spec) => new
|
|
8420
|
+
import { Command as Command109 } from "commander";
|
|
8421
|
+
var infoCommand3 = (spec) => new Command109("info").alias("get").description("show one database: status, storage used, how to connect").argument("<db>", "its name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
8092
8422
|
const client = await managedClient(cmd);
|
|
8093
8423
|
try {
|
|
8094
8424
|
const m = await client.getManaged(spec.kind, name);
|
|
@@ -8100,8 +8430,8 @@ var infoCommand3 = (spec) => new Command103("info").alias("get").description("sh
|
|
|
8100
8430
|
});
|
|
8101
8431
|
|
|
8102
8432
|
// src/commands/managed/link.ts
|
|
8103
|
-
import { Command as
|
|
8104
|
-
var linkCommand2 = (spec) => new
|
|
8433
|
+
import { Command as Command110 } from "commander";
|
|
8434
|
+
var linkCommand2 = (spec) => new Command110("link").description("let a box reach a database privately (same host)").argument("<db>", "the database").argument("<box>", "the box that connects to it").option("--json", "print as JSON").action(async (name, box2, opts, cmd) => {
|
|
8105
8435
|
const client = await managedClient(cmd);
|
|
8106
8436
|
try {
|
|
8107
8437
|
const m = await spin(`linking ${box2} to ${name}\u2026`, client.linkManaged(spec.kind, name, box2));
|
|
@@ -8117,7 +8447,7 @@ var linkCommand2 = (spec) => new Command104("link").description("let a box reach
|
|
|
8117
8447
|
});
|
|
8118
8448
|
|
|
8119
8449
|
// src/commands/managed/ls.ts
|
|
8120
|
-
import { Command as
|
|
8450
|
+
import { Command as Command111 } from "commander";
|
|
8121
8451
|
function listRows(items, user, kindColumn) {
|
|
8122
8452
|
return items.map((m) => ({
|
|
8123
8453
|
owner: m.owner === user ? "private" : m.owner,
|
|
@@ -8131,7 +8461,7 @@ function listRows(items, user, kindColumn) {
|
|
|
8131
8461
|
created: age(m.createdAt)
|
|
8132
8462
|
}));
|
|
8133
8463
|
}
|
|
8134
|
-
var
|
|
8464
|
+
var lsCommand17 = (spec) => new Command111("ls").alias("list").description(spec ? `list your ${spec.title} databases` : "list every managed database, whatever its kind").option("-a, --all", "every one on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
8135
8465
|
const client = await managedClient(cmd);
|
|
8136
8466
|
try {
|
|
8137
8467
|
const items = await client.listManaged(spec?.kind, { all: opts.all });
|
|
@@ -8151,8 +8481,8 @@ var lsCommand16 = (spec) => new Command105("ls").alias("list").description(spec
|
|
|
8151
8481
|
});
|
|
8152
8482
|
|
|
8153
8483
|
// src/commands/managed/password.ts
|
|
8154
|
-
import { Command as
|
|
8155
|
-
var passwordCommand = (spec) => new
|
|
8484
|
+
import { Command as Command112 } from "commander";
|
|
8485
|
+
var passwordCommand = (spec) => new Command112("password").description("show a database's password, or set a new one with --reset").argument("<db>", "its name").option("--reset", "make a new password; the old one stops working").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
8156
8486
|
const client = await managedClient(cmd);
|
|
8157
8487
|
try {
|
|
8158
8488
|
const secret = opts.reset ? await spin(`setting a new password on ${name}\u2026`, client.resetManagedPassword(spec.kind, name)) : await client.managedPassword(spec.kind, name);
|
|
@@ -8168,8 +8498,8 @@ var passwordCommand = (spec) => new Command106("password").description("show a d
|
|
|
8168
8498
|
});
|
|
8169
8499
|
|
|
8170
8500
|
// src/commands/managed/public.ts
|
|
8171
|
-
import { Command as
|
|
8172
|
-
var publicCommand = (spec) => new
|
|
8501
|
+
import { Command as Command113 } from "commander";
|
|
8502
|
+
var publicCommand = (spec) => new Command113("public").description("open a database to the internet, or close it again").argument("<db>", "its name").argument("<state>", "on: reachable from anywhere with the password; off: only linked boxes").option("--json", "print as JSON").action(async (name, state, opts, cmd) => {
|
|
8173
8503
|
if (state !== "on" && state !== "off") throw new KvboxError(`write on or off: kvbox ${spec.command} public ${name} on`);
|
|
8174
8504
|
const client = await managedClient(cmd);
|
|
8175
8505
|
try {
|
|
@@ -8190,8 +8520,8 @@ var publicCommand = (spec) => new Command107("public").description("open a datab
|
|
|
8190
8520
|
});
|
|
8191
8521
|
|
|
8192
8522
|
// src/commands/managed/rm.ts
|
|
8193
|
-
import { Command as
|
|
8194
|
-
var
|
|
8523
|
+
import { Command as Command114 } from "commander";
|
|
8524
|
+
var rmCommand17 = (spec) => new Command114("rm").alias("remove").description("delete a database and all its data").argument("<db>", "its name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
|
|
8195
8525
|
const client = await managedClient(cmd);
|
|
8196
8526
|
try {
|
|
8197
8527
|
if (!await confirm(`Delete database ${name} and all its data? There is no backup.`, opts.yes ?? false)) {
|
|
@@ -8207,8 +8537,8 @@ var rmCommand16 = (spec) => new Command108("rm").alias("remove").description("de
|
|
|
8207
8537
|
});
|
|
8208
8538
|
|
|
8209
8539
|
// src/commands/managed/start.ts
|
|
8210
|
-
import { Command as
|
|
8211
|
-
var startCommand2 = (spec) => new
|
|
8540
|
+
import { Command as Command115 } from "commander";
|
|
8541
|
+
var startCommand2 = (spec) => new Command115("start").description("run a stopped database again").argument("<db>", "its name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
8212
8542
|
const client = await managedClient(cmd);
|
|
8213
8543
|
try {
|
|
8214
8544
|
const m = await spin(`starting ${name}\u2026`, client.startManaged(spec.kind, name));
|
|
@@ -8220,8 +8550,8 @@ var startCommand2 = (spec) => new Command109("start").description("run a stopped
|
|
|
8220
8550
|
});
|
|
8221
8551
|
|
|
8222
8552
|
// src/commands/managed/stop.ts
|
|
8223
|
-
import { Command as
|
|
8224
|
-
var stopCommand2 = (spec) => new
|
|
8553
|
+
import { Command as Command116 } from "commander";
|
|
8554
|
+
var stopCommand2 = (spec) => new Command116("stop").description("shut a database down, keeping its data (only its storage is charged)").argument("<db>", "its name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
8225
8555
|
const client = await managedClient(cmd);
|
|
8226
8556
|
try {
|
|
8227
8557
|
const m = await spin(`stopping ${name}\u2026`, client.stopManaged(spec.kind, name));
|
|
@@ -8233,8 +8563,8 @@ var stopCommand2 = (spec) => new Command110("stop").description("shut a database
|
|
|
8233
8563
|
});
|
|
8234
8564
|
|
|
8235
8565
|
// src/commands/managed/unlink.ts
|
|
8236
|
-
import { Command as
|
|
8237
|
-
var unlinkCommand2 = (spec) => new
|
|
8566
|
+
import { Command as Command117 } from "commander";
|
|
8567
|
+
var unlinkCommand2 = (spec) => new Command117("unlink").description("stop a box from reaching a database").argument("<db>", "the database").argument("<box>", "the box that was linked to it").option("--json", "print as JSON").action(async (name, box2, opts, cmd) => {
|
|
8238
8568
|
const client = await managedClient(cmd);
|
|
8239
8569
|
try {
|
|
8240
8570
|
const m = await spin(`unlinking ${box2} from ${name}\u2026`, client.unlinkManaged(spec.kind, name, box2));
|
|
@@ -8247,11 +8577,11 @@ var unlinkCommand2 = (spec) => new Command111("unlink").description("stop a box
|
|
|
8247
8577
|
|
|
8248
8578
|
// src/commands/managed/kind.ts
|
|
8249
8579
|
function kindCommand(spec, description) {
|
|
8250
|
-
const command = new
|
|
8251
|
-
for (const make of [
|
|
8580
|
+
const command = new Command118(spec.command).aliases(spec.aliases).description(description);
|
|
8581
|
+
for (const make of [createCommand11, lsCommand17, infoCommand3, passwordCommand, publicCommand, linkCommand2, unlinkCommand2, growCommand3, stopCommand2, startCommand2, rmCommand17]) {
|
|
8252
8582
|
command.addCommand(make(spec).option("--org <slug>", "act in this org (- for your personal databases)"));
|
|
8253
8583
|
}
|
|
8254
|
-
command.addCommand(
|
|
8584
|
+
command.addCommand(backupCommand4(spec));
|
|
8255
8585
|
return command;
|
|
8256
8586
|
}
|
|
8257
8587
|
|
|
@@ -8262,14 +8592,14 @@ var pgCommand = kindCommand(POSTGRES2, "managed PostgreSQL: a database kvbox run
|
|
|
8262
8592
|
var redisCommand = kindCommand(REDIS, "managed Redis (Valkey): a Redis kvbox runs for you, private until you link a box or make it public");
|
|
8263
8593
|
|
|
8264
8594
|
// src/commands/managed/index.ts
|
|
8265
|
-
import { Command as
|
|
8266
|
-
var managedCommand = new
|
|
8595
|
+
import { Command as Command119 } from "commander";
|
|
8596
|
+
var managedCommand = new Command119("managed").description(`databases kvbox runs for you, every kind together (${KINDS.map((k) => `${k.title}: kvbox ${k.command}`).join(", ")})`).addCommand(lsCommand17().option("--org <slug>", "act in this org (- for your personal databases)"));
|
|
8267
8597
|
|
|
8268
8598
|
// src/commands/env/index.ts
|
|
8269
|
-
import { Command as
|
|
8599
|
+
import { Command as Command123 } from "commander";
|
|
8270
8600
|
|
|
8271
8601
|
// src/commands/env/ls.ts
|
|
8272
|
-
import { Command as
|
|
8602
|
+
import { Command as Command120 } from "commander";
|
|
8273
8603
|
|
|
8274
8604
|
// src/commands/env/shared.ts
|
|
8275
8605
|
function requireCloud4(client) {
|
|
@@ -8296,7 +8626,7 @@ function firstBootHint(box2, name) {
|
|
|
8296
8626
|
}
|
|
8297
8627
|
|
|
8298
8628
|
// src/commands/env/ls.ts
|
|
8299
|
-
var
|
|
8629
|
+
var lsCommand18 = new Command120("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) => {
|
|
8300
8630
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
8301
8631
|
try {
|
|
8302
8632
|
if (opts.box !== void 0) {
|
|
@@ -8335,8 +8665,8 @@ var lsCommand17 = new Command114("ls").alias("list").description("list the varia
|
|
|
8335
8665
|
});
|
|
8336
8666
|
|
|
8337
8667
|
// src/commands/env/rm.ts
|
|
8338
|
-
import { Command as
|
|
8339
|
-
var
|
|
8668
|
+
import { Command as Command121 } from "commander";
|
|
8669
|
+
var rmCommand18 = new Command121("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) => {
|
|
8340
8670
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
8341
8671
|
try {
|
|
8342
8672
|
const target = opts.box === void 0 ? void 0 : await findBox2(client, opts.box);
|
|
@@ -8373,8 +8703,8 @@ var rmCommand17 = new Command115("rm").alias("remove").description("remove varia
|
|
|
8373
8703
|
});
|
|
8374
8704
|
|
|
8375
8705
|
// src/commands/env/set.ts
|
|
8376
|
-
import { Command as
|
|
8377
|
-
var setCommand2 = new
|
|
8706
|
+
import { Command as Command122 } from "commander";
|
|
8707
|
+
var setCommand2 = new Command122("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) => {
|
|
8378
8708
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
8379
8709
|
try {
|
|
8380
8710
|
const owner = opts.box === void 0 ? requireCloud4(client) : void 0;
|
|
@@ -8411,14 +8741,14 @@ var setCommand2 = new Command116("set").description("add or change a variable; b
|
|
|
8411
8741
|
});
|
|
8412
8742
|
|
|
8413
8743
|
// src/commands/env/index.ts
|
|
8414
|
-
var envCommand = new
|
|
8744
|
+
var envCommand = new Command123("env").description("environment variables every box of yours gets when it starts (secrets too)").addCommand(lsCommand18, { isDefault: true }).addCommand(setCommand2).addCommand(rmCommand18);
|
|
8415
8745
|
for (const cmd of envCommand.commands) cmd.option("--org <slug>", "the org's variables instead of yours");
|
|
8416
8746
|
|
|
8417
8747
|
// src/commands/domain/index.ts
|
|
8418
|
-
import { Command as
|
|
8748
|
+
import { Command as Command127 } from "commander";
|
|
8419
8749
|
|
|
8420
8750
|
// src/commands/domain/add.ts
|
|
8421
|
-
import { Command as
|
|
8751
|
+
import { Command as Command124 } from "commander";
|
|
8422
8752
|
|
|
8423
8753
|
// src/commands/domain/shared.ts
|
|
8424
8754
|
function requireCloud5(client) {
|
|
@@ -8438,7 +8768,7 @@ function hostIn(name, zone) {
|
|
|
8438
8768
|
}
|
|
8439
8769
|
|
|
8440
8770
|
// src/commands/domain/add.ts
|
|
8441
|
-
var addCommand4 = new
|
|
8771
|
+
var addCommand4 = new Command124("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) => {
|
|
8442
8772
|
const domain = assertDomain(domainArg.trim().toLowerCase());
|
|
8443
8773
|
const port = opts.port === void 0 ? void 0 : parsePorts([opts.port])[0];
|
|
8444
8774
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
@@ -8474,8 +8804,8 @@ kvbox checks every minute; ${domain} is served at ${d.url} once its records are
|
|
|
8474
8804
|
});
|
|
8475
8805
|
|
|
8476
8806
|
// src/commands/domain/ls.ts
|
|
8477
|
-
import { Command as
|
|
8478
|
-
var
|
|
8807
|
+
import { Command as Command125 } from "commander";
|
|
8808
|
+
var lsCommand19 = new Command125("ls").alias("list").description("list your custom domains and whether they are live").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
8479
8809
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
8480
8810
|
try {
|
|
8481
8811
|
requireCloud5(client);
|
|
@@ -8504,8 +8834,8 @@ var lsCommand18 = new Command119("ls").alias("list").description("list your cust
|
|
|
8504
8834
|
});
|
|
8505
8835
|
|
|
8506
8836
|
// src/commands/domain/rm.ts
|
|
8507
|
-
import { Command as
|
|
8508
|
-
var
|
|
8837
|
+
import { Command as Command126 } from "commander";
|
|
8838
|
+
var rmCommand19 = new Command126("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) => {
|
|
8509
8839
|
const domain = domainArg.trim().toLowerCase();
|
|
8510
8840
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
8511
8841
|
try {
|
|
@@ -8526,7 +8856,7 @@ var rmCommand18 = new Command120("rm").alias("remove").description("stop serving
|
|
|
8526
8856
|
});
|
|
8527
8857
|
|
|
8528
8858
|
// src/commands/domain/index.ts
|
|
8529
|
-
var domainCommand = new
|
|
8859
|
+
var domainCommand = new Command127("domain").alias("domains").description("serve a box at a domain of your own").addCommand(addCommand4).addCommand(lsCommand19).addCommand(rmCommand19);
|
|
8530
8860
|
for (const cmd of domainCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
8531
8861
|
|
|
8532
8862
|
// src/commands/update.ts
|
|
@@ -8534,7 +8864,7 @@ import { spawn as spawn7 } from "child_process";
|
|
|
8534
8864
|
import { mkdtempSync, rmSync, writeFileSync as writeFileSync2 } from "fs";
|
|
8535
8865
|
import { tmpdir } from "os";
|
|
8536
8866
|
import { join as join9 } from "path";
|
|
8537
|
-
import { Command as
|
|
8867
|
+
import { Command as Command128 } from "commander";
|
|
8538
8868
|
|
|
8539
8869
|
// src/update.ts
|
|
8540
8870
|
import { mkdirSync, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
@@ -8653,7 +8983,7 @@ function run2(cmd, args) {
|
|
|
8653
8983
|
child.on("exit", (code, signal) => resolve4(code ?? (signal ? 1 : 0)));
|
|
8654
8984
|
});
|
|
8655
8985
|
}
|
|
8656
|
-
var selfUpdateCommand = new
|
|
8986
|
+
var selfUpdateCommand = new Command128("update").description("update kvbox to the latest version (reruns the installer from kvbox.sh, agent skill included)").action(async () => {
|
|
8657
8987
|
suppressUpdateNotice();
|
|
8658
8988
|
const inst = installerFor(process.platform, process.env["KVBOX_INSTALL_URL"] || INSTALL_BASE);
|
|
8659
8989
|
let code;
|
|
@@ -8780,7 +9110,7 @@ function installRootHelp(program) {
|
|
|
8780
9110
|
|
|
8781
9111
|
// src/program.ts
|
|
8782
9112
|
function buildProgram() {
|
|
8783
|
-
const program = new
|
|
9113
|
+
const program = new Command129("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 and KVBOX_TOKEN").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();
|
|
8784
9114
|
program.addCommand(vmCommand);
|
|
8785
9115
|
program.addCommand(snapshotsCommand);
|
|
8786
9116
|
program.addCommand(volumeCommand);
|