mirror of
https://github.com/Dokploy/cli.git
synced 2026-07-18 04:15:22 +02:00
refactor: add commands
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { Command, Flags } from "@oclif/core";
|
||||
import axios from "axios";
|
||||
import chalk from "chalk";
|
||||
import inquirer from "inquirer";
|
||||
|
||||
import { readAuthConfig } from "../../utils/utils.js";
|
||||
import { getProject, getProjects } from "../../utils/shared.js";
|
||||
|
||||
export default class ProjectInfo extends Command {
|
||||
static description =
|
||||
@@ -28,35 +28,21 @@ export default class ProjectInfo extends Command {
|
||||
const { flags } = await this.parse(ProjectInfo);
|
||||
|
||||
if (flags.projectId) {
|
||||
// Si se proporciona un projectId, mostrar directamente la información del proyecto
|
||||
await this.showProjectInfo(auth, flags.projectId);
|
||||
} else {
|
||||
// Obtener la lista de proyectos y permitir la selección
|
||||
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
||||
|
||||
try {
|
||||
const response = await axios.get(`${auth.url}/api/trpc/project.all`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${auth.token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.data.result.data.json) {
|
||||
this.error(chalk.red("Error fetching projects"));
|
||||
}
|
||||
|
||||
const projects = response.data.result.data.json;
|
||||
const projects = await getProjects(auth, this);
|
||||
|
||||
if (projects.length === 0) {
|
||||
this.log(chalk.yellow("No projects found."));
|
||||
return;
|
||||
}
|
||||
|
||||
// Permitir al usuario seleccionar un proyecto
|
||||
const answers = await inquirer.prompt([
|
||||
{
|
||||
choices: projects.map((project: any) => ({
|
||||
choices: projects.map((project) => ({
|
||||
name: project.name,
|
||||
value: project.projectId,
|
||||
})),
|
||||
@@ -68,7 +54,7 @@ export default class ProjectInfo extends Command {
|
||||
|
||||
const selectedProjectId = answers.selectedProject;
|
||||
|
||||
await this.showProjectInfo(auth, selectedProjectId);
|
||||
await await this.showProjectInfo(auth, selectedProjectId);
|
||||
} catch (error) {
|
||||
// @ts-expect-error hola
|
||||
this.error(chalk.red(`Failed to fetch project list: ${error.message}`));
|
||||
@@ -85,23 +71,7 @@ export default class ProjectInfo extends Command {
|
||||
);
|
||||
|
||||
try {
|
||||
const response = await axios.get(`${auth.url}/api/trpc/project.one`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${auth.token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
params: {
|
||||
input: JSON.stringify({
|
||||
json: { projectId },
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.data.result.data.json) {
|
||||
this.error(chalk.red("Error fetching project information"));
|
||||
}
|
||||
|
||||
const projectInfo = response.data.result.data.json;
|
||||
const projectInfo = await getProject(projectId, auth, this);
|
||||
|
||||
this.log(chalk.green(`Project Name: ${projectInfo.name}`));
|
||||
this.log(
|
||||
@@ -141,55 +111,55 @@ export default class ProjectInfo extends Command {
|
||||
|
||||
if (projectInfo.applications.length > 0) {
|
||||
this.log(chalk.blue("\nApplications:"));
|
||||
projectInfo.applications.forEach((app: any, index: number) => {
|
||||
projectInfo.applications.forEach((app, index: number) => {
|
||||
this.log(` ${index + 1}. ${app.name}`);
|
||||
});
|
||||
}
|
||||
|
||||
if (projectInfo.compose.length > 0) {
|
||||
this.log(chalk.blue("\nCompose Services:"));
|
||||
projectInfo.compose.forEach((service: any, index: number) => {
|
||||
projectInfo.compose.forEach((service, index: number) => {
|
||||
this.log(` ${index + 1}. ${service.name}`);
|
||||
});
|
||||
}
|
||||
|
||||
if (projectInfo.mariadb.length > 0) {
|
||||
this.log(chalk.blue("\nMariaDB Databases:"));
|
||||
projectInfo.mariadb.forEach((db: any, index: number) => {
|
||||
projectInfo.mariadb.forEach((db, index: number) => {
|
||||
this.log(` ${index + 1}. ${db.name}`);
|
||||
});
|
||||
}
|
||||
|
||||
if (projectInfo.mongo.length > 0) {
|
||||
this.log(chalk.blue("\nMongoDB Databases:"));
|
||||
projectInfo.mongo.forEach((db: any, index: number) => {
|
||||
projectInfo.mongo.forEach((db, index: number) => {
|
||||
this.log(` ${index + 1}. ${db.name}`);
|
||||
});
|
||||
}
|
||||
|
||||
if (projectInfo.mysql.length > 0) {
|
||||
this.log(chalk.blue("\nMySQL Databases:"));
|
||||
projectInfo.mysql.forEach((db: any, index: number) => {
|
||||
projectInfo.mysql.forEach((db, index: number) => {
|
||||
this.log(` ${index + 1}. ${db.name}`);
|
||||
});
|
||||
}
|
||||
|
||||
if (projectInfo.postgres.length > 0) {
|
||||
this.log(chalk.blue("\nPostgreSQL Databases:"));
|
||||
projectInfo.postgres.forEach((db: any, index: number) => {
|
||||
projectInfo.postgres.forEach((db, index: number) => {
|
||||
this.log(` ${index + 1}. ${db.name}`);
|
||||
});
|
||||
}
|
||||
|
||||
if (projectInfo.redis.length > 0) {
|
||||
this.log(chalk.blue("\nRedis Databases:"));
|
||||
projectInfo.redis.forEach((db: any, index: number) => {
|
||||
projectInfo.redis.forEach((db, index: number) => {
|
||||
this.log(` ${index + 1}. ${db.name}`);
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
this.error(
|
||||
// @ts-expect-error hola
|
||||
// @ts-expect-error
|
||||
chalk.red(`Failed to fetch project information: ${error.message}`),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Command } from "@oclif/core";
|
||||
import axios from "axios";
|
||||
import chalk from "chalk";
|
||||
import Table from "cli-table3";
|
||||
|
||||
import { readAuthConfig } from "../../utils/utils.js";
|
||||
import { getProjects } from "../../utils/shared.js";
|
||||
|
||||
export default class ProjectList extends Command {
|
||||
static description = "List all projects.";
|
||||
@@ -16,18 +16,7 @@ export default class ProjectList extends Command {
|
||||
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
||||
|
||||
try {
|
||||
const response = await axios.get(`${auth.url}/api/trpc/project.all`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${auth.token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.data.result.data.json) {
|
||||
this.error(chalk.red("Error fetching projects"));
|
||||
}
|
||||
|
||||
const projects = response.data.result.data.json;
|
||||
const projects = await getProjects(auth, this);
|
||||
|
||||
if (projects.length === 0) {
|
||||
this.log(chalk.yellow("No projects found."));
|
||||
@@ -52,9 +41,9 @@ export default class ProjectList extends Command {
|
||||
|
||||
this.log(table.toString());
|
||||
}
|
||||
} catch {
|
||||
} catch (error) {
|
||||
// @ts-expect-error error is not defined
|
||||
this.error(chalk.red(`Failed to list projects: ${error.message}`));
|
||||
this.error(chalk.red(`Failed to list projects: ${error?.message}`));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user