Implemented count feature

This commit is contained in:
Space-Banane
2026-03-18 16:33:03 +01:00
parent fdcf3d06e0
commit 9aec36d0e8
8 changed files with 305 additions and 6 deletions
+59
View File
@@ -0,0 +1,59 @@
import chalk from "chalk";
import { getApiClient } from "../../api.js";
export const triggersCountDefinition = {
name: "triggers",
description: "Counts the amount of triggers the current user has.",
action: async () => {
await countTriggers();
},
};
async function countTriggers() {
const client = await getApiClient();
try {
const response = await client.get("/api/triggers");
if (response.status === 200 && response.data.data) {
const triggers = response.data.data;
const count = triggers.length;
if (count > 0) {
console.log(chalk.blue("Triggers List:"));
triggers.forEach((t: any) => {
const functionInfo = t.function ? chalk.gray(` [Func: ${t.function.name}]`) : "";
const cronInfo = t.cron ? chalk.yellow(` (Cron: ${t.cron})`) : "";
console.log(`- ${chalk.cyan(t.name)} ${chalk.gray(`(${t.id})`)}${functionInfo}${cronInfo}`);
if (t.description) {
console.log(` ${chalk.italic.gray(t.description)}`);
}
});
console.log("");
}
console.log(
`${chalk.green("✓")} You have ${chalk.bgGreen.black(` ${count} `)} triggers.`,
);
} else {
console.log(
`${chalk.yellow("!")} Unexpected response from server.`,
);
console.log(`Status Code: ${chalk.blue(response.status)}`);
}
} catch (error: any) {
if (error.response) {
console.error(
`${chalk.red("✗")} Failed to fetch trigger count.`,
);
console.error(`Status Code: ${chalk.red(error.response.status)}`);
console.error(
`Message: ${chalk.yellow(error.response.data.message || "Unknown error from server")}`,
);
} else if (error.request) {
console.error(`${chalk.red("✗")} No response received from server.`);
} else {
console.error(`${chalk.red("✗")} Error:`, error.message);
}
}
}