Skip to content

Commit 32eac90

Browse files
refactor!: drop createImagesCommand options
Collapse the shared images factory back to a zero-arg function: - always alias `os` and reference `sf images` in help/next-steps text - always print the envelope shape for `list --json` - delete the unused `sf nodes image` wrapper BREAKING CHANGE: `sf nodes images list --json` and `sf vm images list --json` now print the envelope object instead of a bare array. Scripts using `... --json | jq '.[]'` need to switch to `... | jq '.data[]'`. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 2e1124c commit 32eac90

7 files changed

Lines changed: 20 additions & 70 deletions

File tree

src/lib/images/get.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { logAndQuit } from "../../helpers/errors.ts";
1212
import { formatDate } from "../../helpers/format-time.ts";
1313
import type { components } from "../../schema.ts";
1414
import { Row } from "../Row.tsx";
15-
import type { CreateImagesOptions } from "./index.ts";
1615

1716
dayjs.extend(utc);
1817
dayjs.extend(advanced);
@@ -97,7 +96,7 @@ function formatStatusInk(status: string): React.ReactElement {
9796
}
9897
}
9998

100-
export function createGet(_opts: CreateImagesOptions = {}) {
99+
export function createGet() {
101100
return new Command("get")
102101
.alias("show")
103102
.description("Get image details and download URL")

src/lib/images/index.ts

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,29 @@ import { createGet } from "./get.tsx";
33
import { createList } from "./list.ts";
44
import { createUpload } from "./upload.ts";
55

6-
export interface CreateImagesOptions {
7-
/**
8-
* Path users invoke this command under, used in help text and "next steps"
9-
* suggestions (e.g. `"sf images"`, `"sf nodes images"`, `"sf vm images"`).
10-
* Defaults to `"sf images"`.
11-
*/
12-
parentPath?: string;
13-
/**
14-
* When true, `list --json` prints just the bare image array and `get --json`
15-
* prints just the bare image object. Matches the pre-shared-factory output
16-
* shape of `sf nodes images` / `sf vm images` so existing scripts piping
17-
* `... --json | jq` keep working. Defaults to `false` (envelope shape).
18-
*/
19-
legacyJsonShape?: boolean;
20-
}
21-
22-
export function createImagesCommand(opts: CreateImagesOptions = {}) {
23-
const { parentPath = "sf images", legacyJsonShape = false } = opts;
24-
const subOpts = { parentPath, legacyJsonShape };
6+
export function createImagesCommand() {
257
const images = new Command("images")
268
.alias("image")
9+
.alias("os")
2710
.description("Manage images")
2811
.showHelpAfterError()
2912
.addHelpText(
3013
"after",
3114
`
3215
Examples:\n
3316
\x1b[2m# Upload an image file\x1b[0m
34-
$ ${parentPath} upload -f ./my-image.raw -n my-image
17+
$ sf images upload -f ./my-image.raw -n my-image
3518
3619
\x1b[2m# List all images\x1b[0m
37-
$ ${parentPath} list
20+
$ sf images list
3821
3922
\x1b[2m# Get image details and download URL\x1b[0m
40-
$ ${parentPath} get <image-id>
23+
$ sf images get <image-id>
4124
`,
4225
)
43-
.addCommand(createList(subOpts))
44-
.addCommand(createUpload(subOpts))
45-
.addCommand(createGet(subOpts))
26+
.addCommand(createList())
27+
.addCommand(createUpload())
28+
.addCommand(createGet())
4629
.action(() => {
4730
images.help();
4831
});

src/lib/images/list.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ import ora from "ora";
66
import { apiClient } from "../../apiClient.ts";
77
import { logAndQuit } from "../../helpers/errors.ts";
88
import { formatDate } from "../../helpers/format-time.ts";
9-
import type { CreateImagesOptions } from "./index.ts";
109
import { getDefaultWorkspace } from "./utils.ts";
1110

12-
export function createList(opts: CreateImagesOptions = {}) {
13-
const { parentPath = "sf images", legacyJsonShape = false } = opts;
11+
export function createList() {
1412
return new Command("list")
1513
.alias("ls")
1614
.description("List images")
@@ -21,13 +19,13 @@ export function createList(opts: CreateImagesOptions = {}) {
2119
`
2220
Examples:\n
2321
\x1b[2m# List all images\x1b[0m
24-
$ ${parentPath} list
22+
$ sf images list
2523
2624
\x1b[2m# Get detailed info for a specific image\x1b[0m
27-
$ ${parentPath} get <image-id>
25+
$ sf images get <image-id>
2826
2927
\x1b[2m# List images in JSON format\x1b[0m
30-
$ ${parentPath} list --json
28+
$ sf images list --json
3129
`,
3230
)
3331
.action(async (options) => {
@@ -47,13 +45,7 @@ Examples:\n
4745
}
4846

4947
if (options.json) {
50-
// legacyJsonShape: print just the bare array so existing scripts
51-
// piping `... --json | jq '.[].id'` keep working under `sf nodes
52-
// images list` / `sf vm images list`. Default (envelope) is the
53-
// shape preferred for the new top-level `sf images list`.
54-
console.log(
55-
JSON.stringify(legacyJsonShape ? data.data : data, null, 2),
56-
);
48+
console.log(JSON.stringify(data, null, 2));
5749
return;
5850
}
5951

@@ -62,7 +54,7 @@ Examples:\n
6254
if (images.length === 0) {
6355
console.log("No images found.");
6456
console.log(chalk.gray("\nUpload your first image:"));
65-
console.log(` ${parentPath} upload -f ./my-image.img -n my-image`);
57+
console.log(" sf images upload -f ./my-image.img -n my-image");
6658
return;
6759
}
6860

@@ -100,7 +92,7 @@ Examples:\n
10092
content: chalk.blackBright(
10193
`${images.length - 5} older ${
10294
images.length - 5 === 1 ? "image" : "images"
103-
} not shown. Use ${parentPath} list --json to list all images.`,
95+
} not shown. Use sf images list --json to list all images.`,
10496
),
10597
},
10698
]);
@@ -111,7 +103,7 @@ Examples:\n
111103
console.log(chalk.gray("\nNext steps:"));
112104
const firstImage = sortedImages[0];
113105
if (firstImage) {
114-
console.log(` ${parentPath} get ${chalk.cyan(firstImage.id)}`);
106+
console.log(` sf images get ${chalk.cyan(firstImage.id)}`);
115107
}
116108
const firstCompletedImage = sortedImages.find(
117109
(image) => image.upload_status === "completed",

src/lib/images/upload.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import cliSpinners from "cli-spinners";
1212
import ora, { type Ora } from "ora";
1313
import { apiClient } from "../../apiClient.ts";
1414
import { logAndQuit } from "../../helpers/errors.ts";
15-
import type { CreateImagesOptions } from "./index.ts";
1615
import { getDefaultWorkspace } from "./utils.ts";
1716

1817
async function readChunk(
@@ -54,7 +53,7 @@ async function readChunk(
5453
}
5554
}
5655

57-
export function createUpload(_opts: CreateImagesOptions = {}) {
56+
export function createUpload() {
5857
return new Command("upload")
5958
.description("Upload an image file (multipart)")
6059
.requiredOption("-f, --file <file>", "Path to the image file")

src/lib/nodes/image/index.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/lib/nodes/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import create from "./create.ts";
55
import deleteCommand from "./delete.ts";
66
import extend from "./extend.ts";
77
import get from "./get.tsx";
8-
import createImagesCommand from "./image/index.ts";
8+
import { createImagesCommand } from "../images/index.ts";
99
import list from "./list.tsx";
1010
import logs from "./logs.ts";
1111
import redeploy from "./redeploy.ts";

src/lib/vm/index.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,5 @@ export async function registerVM(program: Command) {
6666
.addCommand(logs)
6767
.addCommand(replace)
6868
.addCommand(script)
69-
.addCommand(
70-
// Preserve the `os` alias and array-shaped `list --json` output that the
71-
// pre-shared-factory `sf vm images` had; help text examples reference
72-
// `sf vm images …` so they match the user's invocation.
73-
createImagesCommand({
74-
parentPath: "sf vm images",
75-
legacyJsonShape: true,
76-
}).alias("os"),
77-
);
69+
.addCommand(createImagesCommand());
7870
}

0 commit comments

Comments
 (0)