feat(cli): add -s alias and generic short option help
This commit is contained in:
26
src/cli.js
26
src/cli.js
@@ -20,7 +20,7 @@ function usage() {
|
||||
|
||||
Commands:
|
||||
list-apps [--display-name|-n <name>]
|
||||
list-app-permissions --app-id|-i <appId> [--resolve|-r]
|
||||
list-app-permissions --app-id|-i <appId> [--resolve|-r] [--short|-s]
|
||||
list-app-grants --app-id|-i <appId>
|
||||
table [--pretty|-p] [--quote-guids|-g]
|
||||
|
||||
@@ -28,6 +28,7 @@ Options:
|
||||
-n, --display-name <name> Filter apps by exact display name
|
||||
-i, --app-id <appId> Application (client) ID
|
||||
-r, --resolve Resolve permission GUIDs to human-readable values
|
||||
-s, --short Makes output more compact
|
||||
-q, --query <jmespath> Filter output JSON using JMESPath
|
||||
-p, --pretty Use normalized column widths for Markdown table output
|
||||
-g, --quote-guids In pretty tables, wrap GUID values in backticks
|
||||
@@ -41,6 +42,17 @@ function outputFiltered(object, query) {
|
||||
: object;
|
||||
}
|
||||
|
||||
function omitPermissionGuidColumns(value) {
|
||||
if (Array.isArray(value)) {
|
||||
return value.map((item) => omitPermissionGuidColumns(item));
|
||||
}
|
||||
if (!value || typeof value !== "object") {
|
||||
return value;
|
||||
}
|
||||
const { resourceAppId, permissionId, ...rest } = value;
|
||||
return rest;
|
||||
}
|
||||
|
||||
async function readJsonFromStdin() {
|
||||
const input = await new Promise((resolve, reject) => {
|
||||
let data = "";
|
||||
@@ -81,6 +93,7 @@ async function main() {
|
||||
"display-name": { type: "string", short: "n" },
|
||||
"app-id": { type: "string", short: "i" },
|
||||
resolve: { type: "boolean", short: "r" },
|
||||
short: { type: "boolean", short: "s" },
|
||||
query: { type: "string", short: "q" },
|
||||
pretty: { type: "boolean", short: "p" },
|
||||
"quote-guids": { type: "boolean", short: "g" },
|
||||
@@ -149,14 +162,17 @@ async function main() {
|
||||
}
|
||||
|
||||
const filtered = outputFiltered(result, values.query);
|
||||
const output = command === "list-app-permissions" && values.short
|
||||
? omitPermissionGuidColumns(filtered)
|
||||
: filtered;
|
||||
if (command === "table") {
|
||||
console.log(toMarkdownTable(filtered, Boolean(values.pretty), Boolean(values["quote-guids"])));
|
||||
console.log(toMarkdownTable(output, Boolean(values.pretty), Boolean(values["quote-guids"])));
|
||||
} else if (outputFormat === "prettytable") {
|
||||
console.log(toMarkdownTable(filtered, true, Boolean(values["quote-guids"])));
|
||||
console.log(toMarkdownTable(output, true, Boolean(values["quote-guids"])));
|
||||
} else if (outputFormat === "table") {
|
||||
console.log(toMarkdownTable(filtered));
|
||||
console.log(toMarkdownTable(output));
|
||||
} else {
|
||||
console.log(JSON.stringify(filtered, null, 2));
|
||||
console.log(JSON.stringify(output, null, 2));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user