Skip to content

Commit

Permalink
fixup! ls: Show keys and values
Browse files Browse the repository at this point in the history
  • Loading branch information
nbrahms committed Feb 26, 2024
1 parent 5bd3e74 commit 1605f16
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/commands/__tests__/__snapshots__/ls.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ Unknown argument: foo",
exports[`ls when valid ls command should print list response 1`] = `
[
[
"instance-1 - Instance 1",
"instance-1[02m - Instance 1[00m",
],
[
"instance-2 - Instance 2",
"instance-2[02m - Instance 2[00m",
],
]
`;
Expand Down
9 changes: 7 additions & 2 deletions src/commands/ls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1605f16

Please sign in to comment.