-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into fix-cli-parity-4
- Loading branch information
Showing
4 changed files
with
77 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import chalk from "chalk"; | ||
import { Command } from "commander"; | ||
import client from "../sdk/client/client"; | ||
import { getOpenAPIClient } from "../sdk/utils/config"; | ||
import { ListActionsV2Data } from "../sdk/client"; | ||
|
||
export default class ActionCommand { | ||
private program: Command; | ||
|
||
constructor(program: Command) { | ||
this.program = program; | ||
this.program | ||
.command("actions") | ||
.description("Composio Actions") | ||
.option( | ||
"-a, --apps <appName>", | ||
"List all actions for the given apps", | ||
(value, previous: string[]) => previous.concat([value]), | ||
[] | ||
) | ||
.option( | ||
"--tags <tagName>", | ||
"List all actions for the given tags", | ||
(value, previous: string[]) => previous.concat([value]), | ||
[] | ||
) | ||
.option( | ||
"--use-case <useCase>", | ||
"Search for actions based on the given use case" | ||
) | ||
.option("--limit <limit>", "Limit the number of actions to display") | ||
.option("--enabled", "Only show enabled actions") | ||
.action(this.handleAction.bind(this)); | ||
} | ||
|
||
private async handleAction(options: { | ||
apps?: string[]; | ||
tags?: string[]; | ||
useCase?: string; | ||
limit?: number; | ||
enabled?: boolean; | ||
}): Promise<void> { | ||
getOpenAPIClient(); | ||
const { apps = [], tags = [], useCase, limit, enabled } = options; | ||
if (apps.length === 0) { | ||
console.log(chalk.red("Please provide at least one app name")); | ||
Check warning on line 46 in js/src/cli/actions.ts
|
||
return; | ||
} | ||
const data: ListActionsV2Data = { | ||
query: { | ||
apps: apps.join(","), | ||
...(tags.length && { tags: tags.join(",") }), | ||
...(limit && { limit }), | ||
...(enabled && { showEnabledOnly: enabled }), | ||
...(useCase && { useCase }), | ||
}, | ||
}; | ||
try { | ||
const response = await client.actionsV2.listActionsV2(data); | ||
if (response.data?.items.length === 0) { | ||
console.log(chalk.yellow("No actions found")); | ||
Check warning on line 61 in js/src/cli/actions.ts
|
||
return; | ||
} | ||
console.log(chalk.green("Here are the actions for the app:")); | ||
Check warning on line 64 in js/src/cli/actions.ts
|
||
console.log(""); | ||
Check warning on line 65 in js/src/cli/actions.ts
|
||
// render list | ||
const actions = response.data?.items || []; | ||
actions.forEach((action) => console.log(action.name)); | ||
Check warning on line 68 in js/src/cli/actions.ts
|
||
} catch (error) { | ||
console.log(chalk.red((error as Error)?.message)); | ||
Check warning on line 70 in js/src/cli/actions.ts
|
||
return; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters