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
+54
View File
@@ -0,0 +1,54 @@
import chalk from "chalk";
import { getApiClient } from "../../api.js";
export const namespacesCountDefinition = {
name: "namespaces",
description: "Counts the amount of namespaces the current user has.",
action: async () => {
await countNamespaces();
},
};
async function countNamespaces() {
const client = await getApiClient();
try {
const response = await client.get("/api/namespaces");
if (response.status === 200 && response.data.data) {
const namespaces = response.data.data;
const count = namespaces.length;
if (count > 0) {
console.log(chalk.blue("Namespaces List:"));
namespaces.forEach((ns: any) => {
console.log(`- ${chalk.cyan(ns.name)} ${chalk.gray(`(${ns.id})`)}`);
});
console.log("");
}
console.log(
`${chalk.green("✓")} You have ${chalk.bgGreen.black(` ${count} `)} namespaces.`,
);
} 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 namespace 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);
}
}
}