refactor(cli): split command dispatcher into per-command handlers

This commit is contained in:
2026-02-08 14:56:47 +01:00
parent 3d03600cef
commit 9f0b4eddd6

View File

@@ -28,20 +28,22 @@ async function getGraphClientFromPublicConfig() {
});
}
export async function runCommand(command, values) {
switch (command) {
case "table":
async function runTableCommand() {
return readJsonFromStdin();
case "list-apps": {
}
async function runListAppsCommand(values) {
const { client } = await getGraphClientFromPublicConfig();
return listApps(client, {
displayName: values["display-name"],
});
}
case "list-app-permissions": {
async function runListAppPermissionsCommand(values) {
if (!values["app-id"]) {
throw new Error("--app-id is required for list-app-permissions");
}
const { client } = await getGraphClientFromPublicConfig();
let result = values.resolve || values.filter
? await listAppPermissionsResolved(client, values["app-id"])
@@ -51,14 +53,17 @@ export async function runCommand(command, values) {
}
return result;
}
case "list-app-grants": {
async function runListAppGrantsCommand(values) {
if (!values["app-id"]) {
throw new Error("--app-id is required for list-app-grants");
}
const { client } = await getGraphClientFromPublicConfig();
return listAppGrants(client, values["app-id"]);
}
case "list-resource-permissions": {
async function runListResourcePermissionsCommand(values) {
if (!values["app-id"] && !values["display-name"]) {
throw new Error("--app-id or --display-name is required for list-resource-permissions");
}
@@ -76,6 +81,19 @@ export async function runCommand(command, values) {
}
return result;
}
export async function runCommand(command, values) {
switch (command) {
case "table":
return runTableCommand();
case "list-apps":
return runListAppsCommand(values);
case "list-app-permissions":
return runListAppPermissionsCommand(values);
case "list-app-grants":
return runListAppGrantsCommand(values);
case "list-resource-permissions":
return runListResourcePermissionsCommand(values);
default:
throw new Error(`Unknown command: ${command}`);
}