31 lines
1.0 KiB
TypeScript
31 lines
1.0 KiB
TypeScript
// 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 <name>] [--app-id|-i <appId>] [--filter|-f <glob>] [global options]
|
|
|
|
Options:
|
|
-n, --display-name <name> Get app by name
|
|
-i, --app-id <appId> Get app by id
|
|
-f, --filter <glob> Filter by app display name glob`;
|
|
}
|
|
|
|
export async function runListAppsCommand(values: CommandValues): Promise<unknown> {
|
|
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;
|
|
}
|