Skip to content

Commit 199a5f8

Browse files
committed
cp dines
1 parent 50af1c4 commit 199a5f8

4 files changed

Lines changed: 51 additions & 14 deletions

File tree

src/cli.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -469,28 +469,28 @@ blueprint
469469
.option("--user <user:uid>", "Run as this user (format: username:uid)")
470470
.option(
471471
"-o, --output [format]",
472-
"Output format: text|json|yaml (default: text)",
472+
"Output format: text|json|yaml (default: json)",
473473
)
474474
.action(async (options) => {
475475
const { createBlueprint } = await import("./commands/blueprint/create.js");
476476
await createBlueprint(options);
477477
});
478478

479479
blueprint
480-
.command("get <id>")
481-
.description("Get blueprint details")
480+
.command("get <name-or-id>")
481+
.description("Get blueprint details by name or ID (IDs start with bpt_)")
482482
.option(
483483
"-o, --output [format]",
484-
"Output format: text|json|yaml (default: text)",
484+
"Output format: text|json|yaml (default: json)",
485485
)
486486
.action(async (id, options) => {
487487
const { getBlueprint } = await import("./commands/blueprint/get.js");
488488
await getBlueprint({ id, ...options });
489489
});
490490

491491
blueprint
492-
.command("logs <id>")
493-
.description("Get blueprint build logs")
492+
.command("logs <name-or-id>")
493+
.description("Get blueprint build logs by name or ID (IDs start with bpt_)")
494494
.option(
495495
"-o, --output [format]",
496496
"Output format: text|json|yaml (default: text)",

src/commands/blueprint/create.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,8 @@ export async function createBlueprint(options: CreateBlueprintOptions) {
6565
launch_parameters: launchParameters as Parameters<typeof client.blueprints.create>[0]["launch_parameters"],
6666
});
6767

68-
// Default: just output the ID for easy scripting
69-
if (!options.output || options.output === "text") {
70-
console.log(blueprint.id);
71-
} else {
72-
output(blueprint, { format: options.output, defaultFormat: "json" });
73-
}
68+
// Default: output JSON
69+
output(blueprint, { format: options.output, defaultFormat: "json" });
7470
} catch (error) {
7571
outputError("Failed to create blueprint", error);
7672
}

src/commands/blueprint/get.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,28 @@ interface GetBlueprintOptions {
1313
export async function getBlueprint(options: GetBlueprintOptions) {
1414
try {
1515
const client = getClient();
16-
const blueprint = await client.blueprints.retrieve(options.id);
16+
17+
let blueprint;
18+
19+
// Check if it's an ID (starts with bpt_) or a name
20+
if (options.id.startsWith("bpt_")) {
21+
// It's an ID, retrieve directly
22+
blueprint = await client.blueprints.retrieve(options.id);
23+
} else {
24+
// It's a name, search for it
25+
const result = await client.blueprints.list({ name: options.id });
26+
const blueprints = result.blueprints || [];
27+
28+
if (blueprints.length === 0) {
29+
outputError(`Blueprint not found: ${options.id}`);
30+
return;
31+
}
32+
33+
// Return the first exact match, or first result if no exact match
34+
blueprint =
35+
blueprints.find((b) => b.name === options.id) || blueprints[0];
36+
}
37+
1738
output(blueprint, { format: options.output, defaultFormat: "json" });
1839
} catch (error) {
1940
outputError("Failed to get blueprint", error);

src/commands/blueprint/logs.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,27 @@ function formatLogs(response: BlueprintBuildLogsListView): void {
134134
export async function getBlueprintLogs(options: BlueprintLogsOptions) {
135135
try {
136136
const client = getClient();
137-
const logs = await client.blueprints.logs(options.id);
137+
138+
let blueprintId = options.id;
139+
140+
// Check if it's an ID (starts with bpt_) or a name
141+
if (!options.id.startsWith("bpt_")) {
142+
// It's a name, search for it
143+
const result = await client.blueprints.list({ name: options.id });
144+
const blueprints = result.blueprints || [];
145+
146+
if (blueprints.length === 0) {
147+
outputError(`Blueprint not found: ${options.id}`);
148+
return;
149+
}
150+
151+
// Use the first exact match, or first result if no exact match
152+
const blueprint =
153+
blueprints.find((b) => b.name === options.id) || blueprints[0];
154+
blueprintId = blueprint.id;
155+
}
156+
157+
const logs = await client.blueprints.logs(blueprintId);
138158

139159
// Pretty print for text output, JSON for others
140160
if (!options.output || options.output === "text") {

0 commit comments

Comments
 (0)