update: adopted new output options. Various optimizations.
Some checks failed
build / build (push) Failing after 15s

This commit is contained in:
2026-03-07 18:49:15 +01:00
parent 059590fde4
commit 88ac901222
5 changed files with 47 additions and 32 deletions

View File

@@ -13,10 +13,7 @@ import { usageLogin } from "./cli/commands/login.ts";
import { usageLogout } from "./cli/commands/logout.ts";
import { usageRest } from "./cli/commands/rest.ts";
import {
normalizeOutputFormat,
outputFiltered,
parseHeaderSpec,
renderOutput,
renderCliOutput,
} from "@slawek/sk-tools";
type CliValues = {
@@ -36,6 +33,7 @@ type CliValues = {
short?: boolean;
filter?: string;
query?: string;
columns?: string;
header?: string;
output?: string;
[key: string]: string | boolean | undefined;
@@ -56,6 +54,7 @@ Commands:
Global options (all commands):
-q, --query <jmespath>
-C, --columns <definition> Column tokens: col (raw), col: (auto), col:Label (custom), exact via = prefix
-o, --output <format> table|t|alignedtable|at|prettytable|pt|tsv
-h, --help
@@ -86,16 +85,6 @@ function usageCommand(command: string): string {
}
}
function omitRecords(record: Record<string, unknown>, names: Set<string>): Record<string, unknown> {
return Object.fromEntries(
Object.entries(record).filter(([key]) => !names.has(key)),
);
}
function isRecord(value: unknown): value is Record<string, unknown> {
return value !== null && typeof value === "object" && !Array.isArray(value);
}
async function main(): Promise<void> {
const argv = process.argv.slice(2);
const command = argv[0];
@@ -128,7 +117,8 @@ async function main(): Promise<void> {
short: { type: "boolean", short: "s" },
filter: { type: "string", short: "f" },
query: { type: "string", short: "q" },
header: { type: "string", short: "H" },
columns: { type: "string", short: "C" },
header: { type: "string" },
output: { type: "string", short: "o" },
},
strict: true,
@@ -142,19 +132,8 @@ async function main(): Promise<void> {
process.exit(0);
}
const outputFormat = normalizeOutputFormat(typedValues.output);
const result = await runCommand(command, typedValues);
const filtered = outputFiltered(result, typedValues.query);
let output: unknown = filtered;
if (command === "list-app-permissions" && typedValues.short && Array.isArray(filtered) && filtered.every(isRecord)) {
const names = new Set(["resourceAppId", "permissionId"]);
output = filtered.map((item) => omitRecords(item, names));
}
const headerSpec = command === "rest"
? parseHeaderSpec(undefined)
: parseHeaderSpec(typedValues.header);
renderOutput(outputFormat, headerSpec, output);
const output = await runCommand(command, typedValues);
renderCliOutput(output, typedValues.output, typedValues.query, typedValues.columns);
}
main().catch((err: unknown) => {