From 1605f16fb09737b9ca9e783ed5c197ee96477530 Mon Sep 17 00:00:00 2001 From: Nathan Brahms Date: Mon, 26 Feb 2024 14:24:50 -0800 Subject: [PATCH] fixup! ls: Show keys and values --- src/commands/__tests__/__snapshots__/ls.test.ts.snap | 4 ++-- src/commands/ls.ts | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/commands/__tests__/__snapshots__/ls.test.ts.snap b/src/commands/__tests__/__snapshots__/ls.test.ts.snap index 76ab4b98..0f96f9ab 100644 --- a/src/commands/__tests__/__snapshots__/ls.test.ts.snap +++ b/src/commands/__tests__/__snapshots__/ls.test.ts.snap @@ -19,10 +19,10 @@ Unknown argument: foo", exports[`ls when valid ls command should print list response 1`] = ` [ [ - "instance-1 - Instance 1", + "instance-1 - Instance 1", ], [ - "instance-2 - Instance 2", + "instance-2 - Instance 2", ], ] `; diff --git a/src/commands/ls.ts b/src/commands/ls.ts index e15b6f01..475180a4 100644 --- a/src/commands/ls.ts +++ b/src/commands/ls.ts @@ -67,10 +67,15 @@ const ls = async ( print2(`Showing${truncationPart} ${argPart}${postfixPart}:`); const isSameValue = data.items.every((i) => !i.group && i.key === i.value); - const longest = max(data.items.map((i) => i.key.length)) || 0; + const maxLength = max(data.items.map((i) => i.key.length)) || 0; for (const item of data.items) { + const tagPart = `${item.group ? `${item.group} | ` : ""}${item.value}`; print1( - isSameValue ? item.key : `${item.key.padEnd(longest)} - ${item.value}` + isSameValue + ? item.key + : maxLength > 30 + ? `${item.key}\n \u001b[02m${tagPart}\u001b[00m` + : `${item.key.padEnd(maxLength)}\u001b[02m - ${tagPart}\u001b[00m` ); } } else {