mirror of
https://github.com/Dokploy/cli.git
synced 2026-07-03 04:55:22 +02:00
feat: add environment selection to database commands
- Introduced environmentId flag to all database commands (create, delete, deploy, stop) for specifying the environment. - Implemented interactive prompts for selecting project and environment if flags are not provided. - Enhanced error handling for cases with no available environments or database instances. - Updated type definitions to include Database for better type safety.
This commit is contained in:
@@ -3,7 +3,7 @@ import axios from "axios";
|
||||
import chalk from "chalk";
|
||||
import inquirer from "inquirer";
|
||||
import { readAuthConfig } from "../../../utils/utils.js";
|
||||
import { getProjects } from "../../../utils/shared.js";
|
||||
import { getProjects, type Database } from "../../../utils/shared.js";
|
||||
import { slugify } from "../../../utils/slug.js";
|
||||
import type { Answers } from "../../app/create.js";
|
||||
|
||||
@@ -18,6 +18,11 @@ export default class DatabaseMongoCreate extends Command {
|
||||
description: "ID of the project",
|
||||
required: false,
|
||||
}),
|
||||
environmentId: Flags.string({
|
||||
char: "e",
|
||||
description: "ID of the environment",
|
||||
required: false,
|
||||
}),
|
||||
name: Flags.string({
|
||||
char: "n",
|
||||
description: "Database name",
|
||||
@@ -60,6 +65,7 @@ export default class DatabaseMongoCreate extends Command {
|
||||
const { flags } = await this.parse(DatabaseMongoCreate);
|
||||
let {
|
||||
projectId,
|
||||
environmentId,
|
||||
name,
|
||||
databaseName,
|
||||
description,
|
||||
@@ -70,10 +76,13 @@ export default class DatabaseMongoCreate extends Command {
|
||||
} = flags;
|
||||
|
||||
// Modo interactivo si no se proporcionan los flags necesarios
|
||||
if (!projectId || !name || !databaseName || !appName || !databasePassword) {
|
||||
if (!projectId || !environmentId || !name || !databaseName || !appName || !databasePassword) {
|
||||
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
||||
const projects = await getProjects(auth, this);
|
||||
|
||||
let selectedProject;
|
||||
|
||||
// 1. Seleccionar proyecto
|
||||
if (!projectId) {
|
||||
const { project } = await inquirer.prompt<Answers>([
|
||||
{
|
||||
@@ -86,9 +95,32 @@ export default class DatabaseMongoCreate extends Command {
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
selectedProject = project;
|
||||
projectId = project.projectId;
|
||||
} else {
|
||||
selectedProject = projects.find(p => p.projectId === projectId);
|
||||
}
|
||||
|
||||
// 2. Seleccionar environment del proyecto
|
||||
if (!environmentId) {
|
||||
if (!selectedProject?.environments || selectedProject.environments.length === 0) {
|
||||
this.error(chalk.yellow("No environments found in this project."));
|
||||
}
|
||||
|
||||
const { environment } = await inquirer.prompt([
|
||||
{
|
||||
choices: selectedProject.environments.map((env) => ({
|
||||
name: `${env.name} (${env.description})`,
|
||||
value: env,
|
||||
})),
|
||||
message: "Select an environment:",
|
||||
name: "environment",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
environmentId = environment.environmentId;
|
||||
}
|
||||
|
||||
if (!name || !databaseName || !appName || !databasePassword) {
|
||||
const dbDetails = await inquirer.prompt([
|
||||
{
|
||||
@@ -182,6 +214,7 @@ export default class DatabaseMongoCreate extends Command {
|
||||
dockerImage,
|
||||
appName,
|
||||
projectId,
|
||||
environmentId,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user