disk 0.8.8 → 0.8.9
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/cli.js +26 -7
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -236,7 +236,7 @@ var Disks = class {
|
|
|
236
236
|
async list(opts) {
|
|
237
237
|
const data = await unwrap(
|
|
238
238
|
this._client.GET("/api/disks", {
|
|
239
|
-
params: { query: { limit: opts?.limit, cursor: opts?.cursor } }
|
|
239
|
+
params: { query: { limit: opts?.limit, cursor: opts?.cursor, name: opts?.name } }
|
|
240
240
|
})
|
|
241
241
|
);
|
|
242
242
|
return data.map(
|
|
@@ -382,6 +382,25 @@ function fail(err) {
|
|
|
382
382
|
}
|
|
383
383
|
process.exit(1);
|
|
384
384
|
}
|
|
385
|
+
function isDiskId(s) {
|
|
386
|
+
return /^(dsk-|fs-)[0-9a-fA-F]+$/.test(s);
|
|
387
|
+
}
|
|
388
|
+
async function resolveDisk(idOrName) {
|
|
389
|
+
if (isDiskId(idOrName)) {
|
|
390
|
+
return getDisk(idOrName);
|
|
391
|
+
}
|
|
392
|
+
const matches = await listDisks({ name: idOrName });
|
|
393
|
+
if (matches.length === 0) {
|
|
394
|
+
throw new ArchilApiError(`No disk found with name '${idOrName}'`, 404);
|
|
395
|
+
}
|
|
396
|
+
if (matches.length > 1) {
|
|
397
|
+
throw new ArchilApiError(
|
|
398
|
+
`Multiple disks match name '${idOrName}' \u2014 pass a disk id (dsk-...) instead`,
|
|
399
|
+
400
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
return matches[0];
|
|
403
|
+
}
|
|
385
404
|
function formatBytes(n) {
|
|
386
405
|
if (n === void 0 || n === null) return void 0;
|
|
387
406
|
if (n < 1024) return `${n} B`;
|
|
@@ -475,9 +494,9 @@ program.command("list").description("List disks in the current region").option("
|
|
|
475
494
|
fail(err);
|
|
476
495
|
}
|
|
477
496
|
});
|
|
478
|
-
program.command("get <id>").description("Show details for a disk").option("-o, --output <format>", "Output format: table | json", "table").action(async (
|
|
497
|
+
program.command("get <id|name>").description("Show details for a disk (accepts a disk id or name)").option("-o, --output <format>", "Output format: table | json", "table").action(async (idOrName, opts) => {
|
|
479
498
|
try {
|
|
480
|
-
const d = await
|
|
499
|
+
const d = await resolveDisk(idOrName);
|
|
481
500
|
if (opts.output === "json") {
|
|
482
501
|
console.log(JSON.stringify(d, null, 2));
|
|
483
502
|
} else {
|
|
@@ -505,18 +524,18 @@ program.command("create <name>").description("Create a new disk").action(async (
|
|
|
505
524
|
fail(err);
|
|
506
525
|
}
|
|
507
526
|
});
|
|
508
|
-
program.command("delete <id>").description("Delete a disk").action(async (
|
|
527
|
+
program.command("delete <id|name>").description("Delete a disk (accepts a disk id or name)").action(async (idOrName) => {
|
|
509
528
|
try {
|
|
510
|
-
const d = await
|
|
529
|
+
const d = await resolveDisk(idOrName);
|
|
511
530
|
await d.delete();
|
|
512
531
|
console.log(`Deleted ${d.organization}/${d.name} (${d.id})`);
|
|
513
532
|
} catch (err) {
|
|
514
533
|
fail(err);
|
|
515
534
|
}
|
|
516
535
|
});
|
|
517
|
-
program.command("exec <id> <command...>").description("Run a command in a container with the disk mounted, return stdout/stderr/exit code").action(async (
|
|
536
|
+
program.command("exec <id|name> <command...>").description("Run a command in a container with the disk mounted, return stdout/stderr/exit code (accepts a disk id or name)").action(async (idOrName, cmd) => {
|
|
518
537
|
try {
|
|
519
|
-
const d = await
|
|
538
|
+
const d = await resolveDisk(idOrName);
|
|
520
539
|
const result = await d.exec(cmd.join(" "));
|
|
521
540
|
if (result.stdout) process.stdout.write(result.stdout);
|
|
522
541
|
if (result.stderr) process.stderr.write(result.stderr);
|
package/dist/index.cjs
CHANGED
|
@@ -278,7 +278,7 @@ var Disks = class {
|
|
|
278
278
|
async list(opts) {
|
|
279
279
|
const data = await unwrap(
|
|
280
280
|
this._client.GET("/api/disks", {
|
|
281
|
-
params: { query: { limit: opts?.limit, cursor: opts?.cursor } }
|
|
281
|
+
params: { query: { limit: opts?.limit, cursor: opts?.cursor, name: opts?.name } }
|
|
282
282
|
})
|
|
283
283
|
);
|
|
284
284
|
return data.map(
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -230,7 +230,7 @@ var Disks = class {
|
|
|
230
230
|
async list(opts) {
|
|
231
231
|
const data = await unwrap(
|
|
232
232
|
this._client.GET("/api/disks", {
|
|
233
|
-
params: { query: { limit: opts?.limit, cursor: opts?.cursor } }
|
|
233
|
+
params: { query: { limit: opts?.limit, cursor: opts?.cursor, name: opts?.name } }
|
|
234
234
|
})
|
|
235
235
|
);
|
|
236
236
|
return data.map(
|