Compare commits

...

3 Commits

Author SHA1 Message Date
xiaoju 5643a06a39 refactor: remove table output format, keep json and yaml only
Table format adds complexity without readability gain over yaml.

Refs #328
2026-05-18 13:56:53 +00:00
xiaoju 36d120b745 fix: table format — horizontal for arrays, vertical for objects
Arrays: horizontal table with HEADER row
Objects: vertical KEY/VALUE table
Primitives: fall back to yaml

小橘 🍊(NEKO Team)
2026-05-18 13:43:50 +00:00
xiaomo bb0f2ca678 Merge pull request 'feat: --format json/yaml/table for all non-interactive commands' (#329) from feat/328-format-option into main 2026-05-18 13:40:19 +00:00
2 changed files with 2 additions and 25 deletions
+1 -1
View File
@@ -40,7 +40,7 @@ function runAction(action: () => Promise<void>): void {
const program = new Command();
program.name("uwf").description("Stateless workflow CLI");
program.option("--format <fmt>", "Output format: json, yaml, table", "json");
program.option("--format <fmt>", "Output format: json or yaml", "json");
const workflow = program.command("workflow").description("Workflow registry and CAS");
+1 -24
View File
@@ -1,24 +1,6 @@
import { stringify } from "yaml";
export type OutputFormat = "json" | "yaml" | "table";
function formatTable(data: Array<Record<string, unknown>>): string {
if (data.length === 0) return "";
const keys = Object.keys(data[0]);
const widths = keys.map((k) => {
let max = k.length;
for (const row of data) {
const len = String(row[k] ?? "").length;
if (len > max) max = len;
}
return max;
});
const header = keys.map((k, i) => k.toUpperCase().padEnd(widths[i])).join(" ");
const rows = data.map((row) =>
keys.map((k, i) => String(row[k] ?? "").padEnd(widths[i])).join(" "),
);
return [header, ...rows].join("\n");
}
export type OutputFormat = "json" | "yaml";
export function formatOutput(data: unknown, format: OutputFormat): string {
switch (format) {
@@ -26,10 +8,5 @@ export function formatOutput(data: unknown, format: OutputFormat): string {
return JSON.stringify(data);
case "yaml":
return stringify(data).trimEnd();
case "table":
if (Array.isArray(data) && data.length > 0 && typeof data[0] === "object" && data[0] !== null) {
return formatTable(data as Array<Record<string, unknown>>);
}
return stringify(data).trimEnd();
}
}