Update: Refactored commands into their own source files.
This commit is contained in:
30
src/cli/commands/list-apps.ts
Normal file
30
src/cli/commands/list-apps.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
// 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;
|
||||
}
|
||||
Reference in New Issue
Block a user