Skip to content

Commit 6244a9e

Browse files
fix(wrangler): Nested object rendering in Containers list/info commands (#10679)
* fix(wrangler): Nested object rendering in Containers list/info commands * Update packages/wrangler/src/containers/containers.ts Co-authored-by: Nikita Sharma <[email protected]> --------- Co-authored-by: Nikita Sharma <[email protected]>
1 parent c563ebe commit 6244a9e

File tree

4 files changed

+156
-161
lines changed

4 files changed

+156
-161
lines changed

.changeset/red-keys-clean.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Fix rendering for nested objects in `containers list` and `containers info [ID]`

packages/wrangler/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
"ws": "catalog:default",
161161
"xdg-app-paths": "^8.3.0",
162162
"xxhash-wasm": "^1.0.1",
163+
"yaml": "^2.8.1",
163164
"yargs": "^17.7.2"
164165
},
165166
"peerDependencies": {

packages/wrangler/src/containers/containers.ts

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { processArgument } from "@cloudflare/cli/args";
99
import { dim, gray } from "@cloudflare/cli/colors";
1010
import { inputPrompt, spinner } from "@cloudflare/cli/interactive";
1111
import { ApiError, ApplicationsService } from "@cloudflare/containers-shared";
12+
import YAML from "yaml";
1213
import { wrap } from "../cloudchamber/helpers/wrap";
1314
import { UserError } from "../errors";
1415
import { isNonInteractiveOrCI } from "../is-interactive";
@@ -116,10 +117,9 @@ export async function infoCommand(
116117
);
117118
}
118119

119-
const details = flatDetails(application);
120120
const applicationDetails = {
121121
label: `${application.name} (${application.created_at})`,
122-
details: details,
122+
details: YAML.stringify(application).split("\n"),
123123
value: application.id,
124124
};
125125
await inputPrompt({
@@ -147,29 +147,6 @@ export async function listCommand(
147147
await listCommandHandle(listArgs, config);
148148
}
149149

150-
function flatDetails<T extends Record<string, unknown>>(
151-
obj: T,
152-
indentLevel = 0
153-
): string[] {
154-
const indent = " ".repeat(indentLevel);
155-
return Object.entries(obj).reduce<string[]>((acc, [key, value]) => {
156-
if (
157-
value !== undefined &&
158-
value !== null &&
159-
typeof value === "object" &&
160-
!Array.isArray(value)
161-
) {
162-
acc.push(`${indent}${key}:`);
163-
acc.push(
164-
...flatDetails(value as Record<string, unknown>, indentLevel + 1)
165-
);
166-
} else if (value !== undefined) {
167-
acc.push(`${indent}${key}: ${value}`);
168-
}
169-
return acc;
170-
}, []);
171-
}
172-
173150
async function listCommandHandle(
174151
_args: StrictYargsOptionsToInterface<typeof listYargs>,
175152
_config: Config
@@ -202,10 +179,9 @@ async function listCommandHandle(
202179
}
203180

204181
const applicationDetails = (a: Application) => {
205-
const details = flatDetails(a);
206182
return {
207183
label: `${a.name} (${a.created_at})`,
208-
details: details,
184+
details: YAML.stringify(a).split("\n"),
209185
value: a.id,
210186
};
211187
};

0 commit comments

Comments
 (0)