// SPDX-License-Identifier: MIT import { listApps } from "../../graph/app.ts"; import { filterByDisplayName, getGraphClientFromPublicConfig } from "./shared.ts"; import type { CommandValues } from "./types.ts"; export function usageListApps(): string { return `Usage: sk-az-tools list-apps [--display-name|-n ] [--app-id|-i ] [--filter|-f ] [global options] Options: --display-name, -n Get app by name --app-id, -i Get app by id --filter, -f Filter by app display name glob`; } export async function runListAppsCommand(values: CommandValues): Promise { const { client } = await getGraphClientFromPublicConfig(); let result = await listApps(client, { displayName: values["display-name"], appId: values["app-id"], }); if (values["app-id"] && result.length > 1) { throw new Error(`Expected a single app for --app-id ${values["app-id"]}, but got ${result.length}`); } if (values.filter) { result = filterByDisplayName(result, values.filter); } return result; }