Add browser profile option and TSV output mode
- add --browser-profile for login and validate browser/profile combinations\n- validate browser options eagerly and keep default-browser behavior when omitted\n- add TSV output format (no header)\n- change header default to auto; add --header original/-H o\n- remove explicit json/j output mode usage and keep JSON as implicit default\n- add tini to Dockerfile entrypoint path to improve signal handling
This commit is contained in:
@@ -48,6 +48,7 @@ async function runLoginCommand(values) {
|
||||
useDeviceCode: Boolean(values["use-device-code"]),
|
||||
noBrowser: Boolean(values["no-browser"]),
|
||||
browser: values.browser,
|
||||
browserProfile: values["browser-profile"],
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -12,13 +12,16 @@ export function outputFiltered(object, query) {
|
||||
|
||||
export function parseHeaderSpec(headerValue) {
|
||||
if (!headerValue) {
|
||||
return { mode: "default" };
|
||||
return { mode: "auto" };
|
||||
}
|
||||
|
||||
const raw = headerValue.trim();
|
||||
if (raw === "" || raw.toLowerCase() === "auto" || raw.toLowerCase() === "a") {
|
||||
return { mode: "auto" };
|
||||
}
|
||||
if (raw.toLowerCase() === "original" || raw.toLowerCase() === "o") {
|
||||
return { mode: "original" };
|
||||
}
|
||||
|
||||
const parts = raw.split(",").map((p) => p.trim()).filter(Boolean);
|
||||
const isMap = parts.some((p) => p.includes(":"));
|
||||
@@ -45,12 +48,71 @@ export function parseHeaderSpec(headerValue) {
|
||||
}
|
||||
|
||||
export function normalizeOutputFormat(outputValue) {
|
||||
const raw = (outputValue ?? "json").toLowerCase();
|
||||
if (raw === "json" || raw === "j") return "json";
|
||||
if (outputValue == null) {
|
||||
return "json";
|
||||
}
|
||||
|
||||
const raw = outputValue.toLowerCase();
|
||||
if (raw === "json") {
|
||||
throw new Error("JSON is the default output. Omit --output to use it.");
|
||||
}
|
||||
if (raw === "j") {
|
||||
throw new Error("JSON is the default output. Omit --output to use it.");
|
||||
}
|
||||
if (raw === "table" || raw === "t") return "table";
|
||||
if (raw === "alignedtable" || raw === "at") return "alignedtable";
|
||||
if (raw === "prettytable" || raw === "pt") return "prettytable";
|
||||
throw new Error("--output must be one of: json|j, table|t, alignedtable|at, prettytable|pt");
|
||||
if (raw === "tsv") return "tsv";
|
||||
throw new Error("--output must be one of: table|t, alignedtable|at, prettytable|pt, tsv");
|
||||
}
|
||||
|
||||
function getScalarRowsAndHeaders(value) {
|
||||
let rows;
|
||||
if (Array.isArray(value)) {
|
||||
rows = value.map((item) =>
|
||||
item && typeof item === "object" && !Array.isArray(item)
|
||||
? item
|
||||
: { value: item },
|
||||
);
|
||||
} else if (value && typeof value === "object") {
|
||||
rows = [value];
|
||||
} else {
|
||||
rows = [{ value }];
|
||||
}
|
||||
|
||||
if (rows.length === 0) {
|
||||
return {
|
||||
headers: ["result"],
|
||||
rows: [{ result: "" }],
|
||||
};
|
||||
}
|
||||
|
||||
const headers = [...new Set(rows.flatMap((row) => Object.keys(row)))]
|
||||
.filter((key) =>
|
||||
rows.every((row) => {
|
||||
const v = row[key];
|
||||
return v == null || typeof v !== "object";
|
||||
}),
|
||||
);
|
||||
|
||||
if (headers.length === 0) {
|
||||
return {
|
||||
headers: ["result"],
|
||||
rows: [{ result: "" }],
|
||||
};
|
||||
}
|
||||
|
||||
return { headers, rows };
|
||||
}
|
||||
|
||||
function toTsv(value) {
|
||||
const { headers, rows } = getScalarRowsAndHeaders(value);
|
||||
const lines = rows.map((row) =>
|
||||
headers
|
||||
.map((header) => (row[header] == null ? "" : String(row[header]).replaceAll("\t", " ").replaceAll("\n", " ")))
|
||||
.join("\t"),
|
||||
);
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
export function omitPermissionGuidColumns(value) {
|
||||
@@ -90,6 +152,11 @@ export async function readJsonFromStdin() {
|
||||
}
|
||||
|
||||
export function renderOutput(command, output, outputFormat, headerSpec) {
|
||||
if (outputFormat === "tsv") {
|
||||
console.log(toTsv(output));
|
||||
return;
|
||||
}
|
||||
|
||||
if (command === "table") {
|
||||
console.log(toMarkdownTable(
|
||||
output,
|
||||
|
||||
Reference in New Issue
Block a user