Refactored usage writing helpers.
This commit is contained in:
89
src/cli.js
89
src/cli.js
@@ -16,31 +16,90 @@ function usage() {
|
||||
return `Usage: sk-az-tools <command> [options]
|
||||
|
||||
Commands:
|
||||
list-apps [--display-name|-n <name>]
|
||||
list-app-permissions --app-id|-i <appId> [--resolve|-r] [--short|-s] [--filter|-f <glob>]
|
||||
list-app-grants --app-id|-i <appId>
|
||||
list-resource-permissions [--app-id|-i <appId> | --display-name|-n <name>]
|
||||
table [--header|-H <spec|auto|a>]
|
||||
list-apps List Entra applications
|
||||
list-app-permissions List required permissions for an app
|
||||
list-app-grants List OAuth2 grants for an app
|
||||
list-resource-permissions List available permissions for a resource app
|
||||
table Render stdin JSON as Markdown table
|
||||
|
||||
Global options (all commands):
|
||||
-q, --query <jmespath>
|
||||
-o, --output <format> json|j|table|t|alignedtable|at|prettytable|pt
|
||||
-h, --help
|
||||
|
||||
Use: sk-az-tools --help <command>
|
||||
or: sk-az-tools <command> --help`;
|
||||
}
|
||||
|
||||
function usageListApps() {
|
||||
return `Usage: sk-az-tools list-apps [--display-name|-n <name>] [global options]
|
||||
|
||||
Options:
|
||||
-n, --display-name <name> Filter apps by exact display name
|
||||
-i, --app-id <appId> Application (client) ID
|
||||
-n, --display-name <name> Filter apps by exact display name`;
|
||||
}
|
||||
|
||||
function usageListAppPermissions() {
|
||||
return `Usage: sk-az-tools list-app-permissions --app-id|-i <appId> [--resolve|-r] [--short|-s] [--filter|-f <glob>] [global options]
|
||||
|
||||
Options:
|
||||
-i, --app-id <appId> Application (client) ID (required)
|
||||
-r, --resolve Resolve permission GUIDs to human-readable values
|
||||
-s, --short Makes output more compact
|
||||
-f, --filter <glob> Filter by permission name glob
|
||||
-q, --query <jmespath> Filter output JSON using JMESPath
|
||||
-H, --header <value> Header mode/spec: auto|a OR "col1, col2" OR "key1: Label 1, key2: Label 2"
|
||||
-o, --output <format> Output format: json|j|table|t|alignedtable|at|prettytable|pt (default: json)
|
||||
-h, --help Show this help message`;
|
||||
-f, --filter <glob> Filter by permission name glob`;
|
||||
}
|
||||
|
||||
function usageListAppGrants() {
|
||||
return `Usage: sk-az-tools list-app-grants --app-id|-i <appId> [global options]
|
||||
|
||||
Options:
|
||||
-i, --app-id <appId> Application (client) ID (required)`;
|
||||
}
|
||||
|
||||
function usageListResourcePermissions() {
|
||||
return `Usage: sk-az-tools list-resource-permissions [--app-id|-i <appId> | --display-name|-n <name>] [--filter|-f <glob>] [global options]
|
||||
|
||||
Options:
|
||||
-i, --app-id <appId> Resource app ID
|
||||
-n, --display-name <name> Resource app display name
|
||||
-f, --filter <glob> Filter by permission name glob`;
|
||||
}
|
||||
|
||||
function usageTable() {
|
||||
return `Usage: sk-az-tools table [--header|-H <spec|auto|a>] [global options]
|
||||
|
||||
Options:
|
||||
-H, --header <value> Header mode/spec: auto|a OR "col1, col2" OR "key1: Label 1, key2: Label 2"`;
|
||||
}
|
||||
|
||||
function usageCommand(command) {
|
||||
switch (command) {
|
||||
case "list-apps":
|
||||
return usageListApps();
|
||||
case "list-app-permissions":
|
||||
return usageListAppPermissions();
|
||||
case "list-app-grants":
|
||||
return usageListAppGrants();
|
||||
case "list-resource-permissions":
|
||||
return usageListResourcePermissions();
|
||||
case "table":
|
||||
return usageTable();
|
||||
default:
|
||||
return `Unknown command: ${command}\n\n${usage()}`;
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const argv = process.argv.slice(2);
|
||||
const command = argv[0];
|
||||
if (command === "-h" || command === "--help") {
|
||||
if (!command) {
|
||||
console.log(usage());
|
||||
process.exit(0);
|
||||
}
|
||||
if (command === "-h" || command === "--help") {
|
||||
const helpCommand = argv[1];
|
||||
console.log(helpCommand ? usageCommand(helpCommand) : usage());
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const { values } = parseArgs({
|
||||
args: argv.slice(1),
|
||||
@@ -59,8 +118,8 @@ async function main() {
|
||||
allowPositionals: false,
|
||||
});
|
||||
|
||||
if (values.help || !command) {
|
||||
console.log(usage());
|
||||
if (values.help) {
|
||||
console.log(usageCommand(command));
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user