Migrated from parseArgs from node:util to commander.js.
All checks were successful
build / build (push) Successful in 14s
All checks were successful
build / build (push) Successful in 14s
This commit is contained in:
@@ -4,7 +4,13 @@ import { listAppPermissions, listAppPermissionsResolved } from "../../graph/app.
|
||||
|
||||
import { filterByPermissionName } from "./shared.ts";
|
||||
import { getGraphClient } from "../../graph/index.ts";
|
||||
import type { CommandValues } from "./types.ts";
|
||||
|
||||
type ListAppPermissionsOptions = {
|
||||
appId?: string;
|
||||
resolve?: boolean;
|
||||
short?: boolean;
|
||||
filter?: string;
|
||||
};
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return value !== null && typeof value === "object" && !Array.isArray(value);
|
||||
@@ -33,20 +39,20 @@ Options:
|
||||
--filter, -f <glob> Filter by permission name glob`;
|
||||
}
|
||||
|
||||
export async function runListAppPermissionsCommand(values: CommandValues): Promise<unknown> {
|
||||
if (!values["app-id"]) {
|
||||
export async function runListAppPermissionsCommand(options: ListAppPermissionsOptions): Promise<unknown> {
|
||||
if (!options.appId) {
|
||||
throw new Error("--app-id is required for list-app-permissions");
|
||||
}
|
||||
|
||||
const client = await getGraphClient();
|
||||
let result: unknown = values.resolve || values.filter
|
||||
? await listAppPermissionsResolved(client, values["app-id"])
|
||||
: await listAppPermissions(client, values["app-id"]);
|
||||
if (values.short) {
|
||||
let result: unknown = options.resolve || options.filter
|
||||
? await listAppPermissionsResolved(client, options.appId)
|
||||
: await listAppPermissions(client, options.appId);
|
||||
if (options.short) {
|
||||
result = omitColumns(result, ["resourceAppId", "permissionId"]);
|
||||
}
|
||||
if (values.filter) {
|
||||
result = filterByPermissionName(result as Array<Record<string, unknown>>, values.filter);
|
||||
if (options.filter) {
|
||||
result = filterByPermissionName(result as Array<Record<string, unknown>>, options.filter);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user