Add support for CSV and TSV input formats in table command
All checks were successful
build / build (push) Successful in 12s

This commit is contained in:
2026-03-06 11:43:47 +01:00
parent 21b6a51330
commit 8cbd1d6399
7 changed files with 133 additions and 9 deletions

View File

@@ -1,14 +1,28 @@
// SPDX-License-Identifier: MIT
import { readJsonFromStdin } from "../utils.ts";
import { readCsvFromStdin, readJsonFromStdin } from "../utils.ts";
import type { CommandValues } from "./types.ts";
export function usageTable(): string {
return `Usage: sk-az-tools table [--header|-H <definition|auto|a|original|o>] [global options]
return `Usage: sk-az-tools table [--from|-F <json|csv|tsv>] [--header|-H <definition|auto|a|original|o>] [global options]
Options:
-H, --header <value> Header mode: auto|a (default), original|o, or "col1, col2" or "key1: Label 1, key2: Label 2"`;
--from, -F <json|csv|tsv> Input format on stdin (default: json)
--header, -H <value> Header mode: auto|a (default), original|o, or "col1, col2" or "key1: Label 1, key2: Label 2"`;
}
export async function runTableCommand(): Promise<unknown> {
return readJsonFromStdin();
export async function runTableCommand(values: CommandValues): Promise<unknown> {
const from = (values.from ?? "json").toString().trim().toLowerCase();
if (from === "json") {
return readJsonFromStdin();
}
if (from === "csv") {
return readCsvFromStdin(",");
}
if (from === "tsv") {
return readCsvFromStdin("\t");
}
throw new Error(`Invalid --from '${values.from}'. Allowed: json, csv, tsv`);
}

View File

@@ -3,6 +3,7 @@
export type CommandValues = {
[key: string]: string | boolean | undefined;
type?: string;
from?: string;
method?: string;
url?: string;
header?: string;