@kvbox/cli 0.5.23 → 0.5.24

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 CHANGED
@@ -164,7 +164,7 @@ function versionOf(srcFileUrl, injected) {
164
164
  }
165
165
 
166
166
  // src/version.ts
167
- var VERSION = versionOf(import.meta.url, true ? "0.5.23" : void 0);
167
+ var VERSION = versionOf(import.meta.url, true ? "0.5.24" : void 0);
168
168
 
169
169
  // src/commands/vm/index.ts
170
170
  import { Command as Command26 } from "commander";
@@ -496,9 +496,9 @@ var CreateVolumeRequest = z2.object({
496
496
  name: z2.string(),
497
497
  sizeGib: z2.number().int().min(1).max(MAX_VOLUME_GIB),
498
498
  /**
499
- * Through a control plane (#91): the box this volume is for, so it is made on that box's host. A
500
- * volume attaches only to a box on its own host. Absent: the host with the most room for volumes.
501
- * A host ignores it.
499
+ * Through a control plane (#91): the box this volume is for, so it is made on that box's host; the
500
+ * control plane requires it (a volume attaches only to a box on its own host, so one made for no box
501
+ * could never attach) and the CLI attaches right after. A host ignores it.
502
502
  */
503
503
  box: z2.string().optional()
504
504
  });
@@ -3556,6 +3556,10 @@ import { Command as Command56 } from "commander";
3556
3556
 
3557
3557
  // src/commands/volume/attach.ts
3558
3558
  import { Command as Command51 } from "commander";
3559
+ function describeMount(machine, volume, box) {
3560
+ const path = machine.volumes?.find((v) => volume === v.name || volume.endsWith(`/${v.name}`))?.mountPath ?? volumeMountPath(volume.slice(volume.lastIndexOf("/") + 1));
3561
+ return machine.status === "running" ? ` the box was restarted; the volume is at ${path} inside it` : ` box ${box} is ${machine.status}; the volume is at ${path} once it runs`;
3562
+ }
3559
3563
  var attachCommand = new Command51("attach").description("attach a volume to a box at /mnt/<volume> (a running box is restarted to take it)").argument("<volume>", "volume name").argument("<box>", "box name").option("--json", "print the box as JSON").action(async (volume, box, opts, cmd) => {
3560
3564
  const client = await clientFor(cmd.optsWithGlobals());
3561
3565
  try {
@@ -3564,9 +3568,8 @@ var attachCommand = new Command51("attach").description("attach a volume to a bo
3564
3568
  json(machine);
3565
3569
  return;
3566
3570
  }
3567
- const path = machine.volumes?.find((v) => volume === v.name || volume.endsWith(`/${v.name}`))?.mountPath ?? volumeMountPath(volume.slice(volume.lastIndexOf("/") + 1));
3568
3571
  info(`${color.green("\u2713")} volume ${volume} attached to box ${box}`);
3569
- info(machine.status === "running" ? ` the box was restarted; the volume is at ${path} inside it` : ` box ${box} is ${machine.status}; the volume is at ${path} once it runs`);
3572
+ info(describeMount(machine, volume, box));
3570
3573
  } finally {
3571
3574
  await client.close();
3572
3575
  }
@@ -3581,13 +3584,25 @@ function parseGib2(text2) {
3581
3584
  if (gib > MAX_VOLUME_GIB) throw new KvboxError(`--size ${text2}: a volume is at most ${MAX_VOLUME_GIB} GB`);
3582
3585
  return gib;
3583
3586
  }
3584
- var createCommand = new Command52("create").alias("new").description("create a volume: an empty disk of its own, ready to attach to a box").argument("<name>", "volume name (1-12 chars; the box mounts it at /mnt/<name>)").requiredOption("--size <gb>", "size in GB, like 50 or 50GB (whole GB; it only occupies what is written)").option("--box <box>", "the box it is for: made on that box's host (a volume attaches only to a box on its own host)").option("--json", "print the volume as JSON").action(async (name, opts, cmd) => {
3587
+ var createCommand = new Command52("create").alias("new").description("create a volume for a box: an empty disk of its own at /mnt/<name> inside it (a running box is restarted)").argument("<name>", "volume name (1-12 chars; the box mounts it at /mnt/<name>)").requiredOption("--size <gb>", "size in GB, like 50 or 50GB (whole GB; it only occupies what is written)").option("--box <box>", "the box it is for: made on that box's host and attached to it (required on kvbox.sh; optional with --local)").option("--json", "print the volume as JSON").action(async (name, opts, cmd) => {
3585
3588
  const sizeGib = parseGib2(opts.size);
3586
3589
  const client = await clientFor(cmd.optsWithGlobals());
3587
3590
  try {
3591
+ if (opts.box === void 0 && client.target.kind === "cloud") {
3592
+ throw new KvboxError(`a volume is made for a box, on that box's host: kvbox volume create ${name} --size ${sizeGib} --box <box>`);
3593
+ }
3588
3594
  const vol = await spin(`creating volume ${name} (${sizeGib} GB)\u2026`, client.createVolume({ name, sizeGib, ...opts.box !== void 0 ? { box: opts.box } : {} }));
3589
- if (opts.json) json(vol);
3590
- else info(`${color.green("\u2713")} volume ${name} created (${vol.sizeGib} GB); attach it to a box with: kvbox volume attach ${name} ${opts.box ?? "<box>"}`);
3595
+ if (opts.box === void 0) {
3596
+ if (opts.json) json(vol);
3597
+ else info(`${color.green("\u2713")} volume ${name} created (${vol.sizeGib} GB); attach it to a box with: kvbox volume attach ${name} <box>`);
3598
+ return;
3599
+ }
3600
+ const machine = await spin(`attaching volume ${name} to box ${opts.box} (a running box is restarted)\u2026`, client.attachVolume(name, { box: opts.box }));
3601
+ if (opts.json) json({ ...vol, attachedTo: machine.name });
3602
+ else {
3603
+ info(`${color.green("\u2713")} volume ${name} created (${vol.sizeGib} GB) and attached to box ${opts.box}`);
3604
+ info(describeMount(machine, name, opts.box));
3605
+ }
3591
3606
  } finally {
3592
3607
  await client.close();
3593
3608
  }