@dokploy/cli 0.2.3 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/dist/commands/app/create.d.ts +4 -0
- package/dist/commands/app/create.js +87 -37
- package/dist/commands/app/delete.d.ts +2 -0
- package/dist/commands/app/delete.js +50 -28
- package/dist/commands/app/deploy.d.ts +5 -0
- package/dist/commands/app/deploy.js +93 -55
- package/dist/commands/app/stop.d.ts +5 -0
- package/dist/commands/app/stop.js +87 -54
- package/dist/commands/database/mariadb/create.d.ts +9 -0
- package/dist/commands/database/mariadb/create.js +160 -66
- package/dist/commands/database/mariadb/delete.d.ts +2 -0
- package/dist/commands/database/mariadb/delete.js +56 -47
- package/dist/commands/database/mariadb/deploy.d.ts +5 -0
- package/dist/commands/database/mariadb/deploy.js +88 -54
- package/dist/commands/database/mariadb/stop.d.ts +5 -0
- package/dist/commands/database/mariadb/stop.js +88 -54
- package/dist/commands/database/mongo/create.d.ts +8 -0
- package/dist/commands/database/mongo/create.js +145 -76
- package/dist/commands/database/mongo/delete.d.ts +2 -0
- package/dist/commands/database/mongo/delete.js +56 -45
- package/dist/commands/database/mongo/deploy.d.ts +5 -0
- package/dist/commands/database/mongo/deploy.js +88 -54
- package/dist/commands/database/mongo/stop.d.ts +5 -0
- package/dist/commands/database/mongo/stop.js +88 -54
- package/dist/commands/database/mysql/create.d.ts +9 -0
- package/dist/commands/database/mysql/create.js +168 -81
- package/dist/commands/database/mysql/delete.d.ts +2 -0
- package/dist/commands/database/mysql/delete.js +56 -47
- package/dist/commands/database/mysql/deploy.js +70 -53
- package/dist/commands/database/mysql/stop.js +70 -53
- package/dist/commands/database/postgres/create.d.ts +8 -0
- package/dist/commands/database/postgres/create.js +155 -76
- package/dist/commands/database/postgres/delete.d.ts +2 -0
- package/dist/commands/database/postgres/delete.js +56 -44
- package/dist/commands/database/postgres/deploy.d.ts +5 -0
- package/dist/commands/database/postgres/deploy.js +90 -56
- package/dist/commands/database/postgres/stop.d.ts +5 -0
- package/dist/commands/database/postgres/stop.js +91 -57
- package/dist/commands/database/redis/create.d.ts +6 -0
- package/dist/commands/database/redis/create.js +129 -65
- package/dist/commands/database/redis/delete.d.ts +2 -0
- package/dist/commands/database/redis/delete.js +60 -50
- package/dist/commands/database/redis/deploy.d.ts +5 -0
- package/dist/commands/database/redis/deploy.js +90 -56
- package/dist/commands/database/redis/stop.d.ts +5 -0
- package/dist/commands/database/redis/stop.js +91 -57
- package/dist/commands/env/pull.d.ts +10 -0
- package/dist/commands/env/pull.js +68 -0
- package/dist/commands/env/push.d.ts +10 -0
- package/dist/commands/env/push.js +106 -0
- package/dist/commands/project/create.d.ts +2 -1
- package/dist/commands/project/create.js +53 -34
- package/dist/utils/utils.js +9 -2
- package/oclif.manifest.json +895 -110
- package/package.json +3 -2
- package/{README.md → readme.md} +16 -1
|
@@ -1,69 +1,103 @@
|
|
|
1
|
-
import { Command } from "@oclif/core";
|
|
1
|
+
import { Command, Flags } from "@oclif/core";
|
|
2
|
+
import { readAuthConfig } from "../../../utils/utils.js";
|
|
2
3
|
import chalk from "chalk";
|
|
4
|
+
import { getProject, getProjects } from "../../../utils/shared.js";
|
|
3
5
|
import inquirer from "inquirer";
|
|
4
6
|
import axios from "axios";
|
|
5
|
-
import { getProject, getProjects } from "../../../utils/shared.js";
|
|
6
|
-
import { readAuthConfig } from "../../../utils/utils.js";
|
|
7
7
|
export default class DatabasePostgresStop extends Command {
|
|
8
|
-
static description = "Stop
|
|
8
|
+
static description = "Stop a PostgreSQL instance in a project.";
|
|
9
9
|
static examples = ["$ <%= config.bin %> postgres stop"];
|
|
10
|
+
static flags = {
|
|
11
|
+
projectId: Flags.string({
|
|
12
|
+
char: "p",
|
|
13
|
+
description: "ID of the project",
|
|
14
|
+
required: false,
|
|
15
|
+
}),
|
|
16
|
+
postgresId: Flags.string({
|
|
17
|
+
char: "d",
|
|
18
|
+
description: "ID of the PostgreSQL instance to stop",
|
|
19
|
+
required: false,
|
|
20
|
+
}),
|
|
21
|
+
skipConfirm: Flags.boolean({
|
|
22
|
+
char: "y",
|
|
23
|
+
description: "Skip confirmation prompt",
|
|
24
|
+
default: false,
|
|
25
|
+
}),
|
|
26
|
+
};
|
|
10
27
|
async run() {
|
|
11
28
|
const auth = await readAuthConfig(this);
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
const { flags } = await this.parse(DatabasePostgresStop);
|
|
30
|
+
let { projectId, postgresId } = flags;
|
|
31
|
+
// Modo interactivo si no se proporcionan los flags necesarios
|
|
32
|
+
if (!projectId || !postgresId) {
|
|
33
|
+
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
|
34
|
+
const projects = await getProjects(auth, this);
|
|
35
|
+
if (!projectId) {
|
|
36
|
+
const { project } = await inquirer.prompt([
|
|
37
|
+
{
|
|
38
|
+
choices: projects.map((project) => ({
|
|
39
|
+
name: project.name,
|
|
40
|
+
value: project,
|
|
41
|
+
})),
|
|
42
|
+
message: "Select a project to stop the PostgreSQL instance from:",
|
|
43
|
+
name: "project",
|
|
44
|
+
type: "list",
|
|
45
|
+
},
|
|
46
|
+
]);
|
|
47
|
+
projectId = project.projectId;
|
|
48
|
+
}
|
|
49
|
+
const projectSelected = await getProject(projectId, auth, this);
|
|
50
|
+
if (projectSelected.postgres.length === 0) {
|
|
51
|
+
this.error(chalk.yellow("No PostgreSQL instances found in this project."));
|
|
52
|
+
}
|
|
53
|
+
if (!postgresId) {
|
|
54
|
+
const dbAnswers = await inquirer.prompt([
|
|
55
|
+
{
|
|
56
|
+
// @ts-ignore
|
|
57
|
+
choices: projectSelected.postgres.map((db) => ({
|
|
58
|
+
name: db.name,
|
|
59
|
+
value: db.postgresId,
|
|
60
|
+
})),
|
|
61
|
+
message: "Select the PostgreSQL instance to stop:",
|
|
62
|
+
name: "selectedDb",
|
|
63
|
+
type: "list",
|
|
64
|
+
},
|
|
65
|
+
]);
|
|
66
|
+
postgresId = dbAnswers.selectedDb;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// Confirmar si no se especifica --skipConfirm
|
|
70
|
+
if (!flags.skipConfirm) {
|
|
71
|
+
const confirmAnswers = await inquirer.prompt([
|
|
72
|
+
{
|
|
73
|
+
default: false,
|
|
74
|
+
message: "Are you sure you want to stop this PostgreSQL instance?",
|
|
75
|
+
name: "confirmStop",
|
|
76
|
+
type: "confirm",
|
|
77
|
+
},
|
|
78
|
+
]);
|
|
79
|
+
if (!confirmAnswers.confirmStop) {
|
|
80
|
+
this.error(chalk.yellow("PostgreSQL stop cancelled."));
|
|
81
|
+
}
|
|
29
82
|
}
|
|
30
|
-
|
|
31
|
-
{
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
default: false,
|
|
46
|
-
message: "Are you sure you want to stop this postgres?",
|
|
47
|
-
name: "confirmDelete",
|
|
48
|
-
type: "confirm",
|
|
49
|
-
},
|
|
50
|
-
]);
|
|
51
|
-
if (!confirmAnswers.confirmDelete) {
|
|
52
|
-
this.error(chalk.yellow("postgres stop cancelled."));
|
|
83
|
+
try {
|
|
84
|
+
const response = await axios.post(`${auth.url}/api/trpc/postgres.stop`, {
|
|
85
|
+
json: {
|
|
86
|
+
postgresId,
|
|
87
|
+
},
|
|
88
|
+
}, {
|
|
89
|
+
headers: {
|
|
90
|
+
Authorization: `Bearer ${auth.token}`,
|
|
91
|
+
"Content-Type": "application/json",
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
if (response.status !== 200) {
|
|
95
|
+
this.error(chalk.red("Error stopping PostgreSQL instance"));
|
|
96
|
+
}
|
|
97
|
+
this.log(chalk.green("PostgreSQL instance stopped successfully."));
|
|
53
98
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
postgresId,
|
|
57
|
-
},
|
|
58
|
-
}, {
|
|
59
|
-
headers: {
|
|
60
|
-
Authorization: `Bearer ${auth.token}`,
|
|
61
|
-
"Content-Type": "application/json",
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
if (response.status !== 200) {
|
|
65
|
-
this.error(chalk.red("Error stopping postgres"));
|
|
99
|
+
catch (error) {
|
|
100
|
+
this.error(chalk.red(`Error stopping PostgreSQL instance: ${error.message}`));
|
|
66
101
|
}
|
|
67
|
-
this.log(chalk.green("Postgres stop successful."));
|
|
68
102
|
}
|
|
69
103
|
}
|
|
@@ -4,6 +4,12 @@ export default class DatabaseRedisCreate extends Command {
|
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|
|
6
6
|
projectId: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
7
|
+
name: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
8
|
+
description: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
9
|
+
databasePassword: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
10
|
+
dockerImage: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
11
|
+
skipConfirm: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
12
|
+
appName: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
7
13
|
};
|
|
8
14
|
run(): Promise<void>;
|
|
9
15
|
}
|
|
@@ -6,7 +6,7 @@ import { slugify } from "../../../utils/slug.js";
|
|
|
6
6
|
import { readAuthConfig } from "../../../utils/utils.js";
|
|
7
7
|
import { getProjects } from "../../../utils/shared.js";
|
|
8
8
|
export default class DatabaseRedisCreate extends Command {
|
|
9
|
-
static description = "Create a new Redis
|
|
9
|
+
static description = "Create a new Redis instance within a project.";
|
|
10
10
|
static examples = ["$ <%= config.bin %> redis create"];
|
|
11
11
|
static flags = {
|
|
12
12
|
projectId: Flags.string({
|
|
@@ -14,82 +14,146 @@ export default class DatabaseRedisCreate extends Command {
|
|
|
14
14
|
description: "ID of the project",
|
|
15
15
|
required: false,
|
|
16
16
|
}),
|
|
17
|
+
name: Flags.string({
|
|
18
|
+
char: "n",
|
|
19
|
+
description: "Instance name",
|
|
20
|
+
required: false,
|
|
21
|
+
}),
|
|
22
|
+
description: Flags.string({
|
|
23
|
+
char: "d",
|
|
24
|
+
description: "Instance description",
|
|
25
|
+
required: false,
|
|
26
|
+
}),
|
|
27
|
+
databasePassword: Flags.string({
|
|
28
|
+
description: "Redis password",
|
|
29
|
+
required: false,
|
|
30
|
+
}),
|
|
31
|
+
dockerImage: Flags.string({
|
|
32
|
+
description: "Docker image",
|
|
33
|
+
default: "redis:7",
|
|
34
|
+
}),
|
|
35
|
+
skipConfirm: Flags.boolean({
|
|
36
|
+
char: "y",
|
|
37
|
+
description: "Skip confirmation prompt",
|
|
38
|
+
default: false,
|
|
39
|
+
}),
|
|
40
|
+
appName: Flags.string({
|
|
41
|
+
description: "App name",
|
|
42
|
+
required: false,
|
|
43
|
+
}),
|
|
17
44
|
};
|
|
18
45
|
async run() {
|
|
19
46
|
const auth = await readAuthConfig(this);
|
|
20
47
|
const { flags } = await this.parse(DatabaseRedisCreate);
|
|
21
|
-
let { projectId } = flags;
|
|
22
|
-
|
|
48
|
+
let { projectId, name, description, databasePassword, dockerImage, appName } = flags;
|
|
49
|
+
// Modo interactivo si no se proporcionan los flags necesarios
|
|
50
|
+
if (!projectId || !name || !appName || !databasePassword) {
|
|
23
51
|
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
|
24
52
|
const projects = await getProjects(auth, this);
|
|
25
|
-
|
|
53
|
+
if (!projectId) {
|
|
54
|
+
const { project } = await inquirer.prompt([
|
|
55
|
+
{
|
|
56
|
+
choices: projects.map((project) => ({
|
|
57
|
+
name: project.name,
|
|
58
|
+
value: project,
|
|
59
|
+
})),
|
|
60
|
+
message: "Select a project to create the Redis instance in:",
|
|
61
|
+
name: "project",
|
|
62
|
+
type: "list",
|
|
63
|
+
},
|
|
64
|
+
]);
|
|
65
|
+
projectId = project.projectId;
|
|
66
|
+
}
|
|
67
|
+
if (!name || !appName || !databasePassword) {
|
|
68
|
+
const redisDetails = await inquirer.prompt([
|
|
69
|
+
{
|
|
70
|
+
message: "Enter the name:",
|
|
71
|
+
name: "name",
|
|
72
|
+
type: "input",
|
|
73
|
+
validate: (input) => (input ? true : "Instance name is required"),
|
|
74
|
+
default: name,
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
message: "Enter the instance description (optional):",
|
|
78
|
+
name: "description",
|
|
79
|
+
type: "input",
|
|
80
|
+
default: description,
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
message: "Redis password:",
|
|
84
|
+
name: "databasePassword",
|
|
85
|
+
type: "password",
|
|
86
|
+
default: databasePassword,
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
default: dockerImage || "redis:7",
|
|
90
|
+
message: "Docker Image (default: redis:7):",
|
|
91
|
+
name: "dockerImage",
|
|
92
|
+
type: "input",
|
|
93
|
+
},
|
|
94
|
+
]);
|
|
95
|
+
name = redisDetails.name;
|
|
96
|
+
description = redisDetails.description;
|
|
97
|
+
databasePassword = redisDetails.databasePassword;
|
|
98
|
+
dockerImage = redisDetails.dockerImage;
|
|
99
|
+
const appNamePrompt = await inquirer.prompt([
|
|
100
|
+
{
|
|
101
|
+
default: appName || `${slugify(name)}`,
|
|
102
|
+
message: "Enter the App name:",
|
|
103
|
+
name: "appName",
|
|
104
|
+
type: "input",
|
|
105
|
+
validate: (input) => (input ? true : "App name is required"),
|
|
106
|
+
},
|
|
107
|
+
]);
|
|
108
|
+
appName = appNamePrompt.appName;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// Confirmar si no se especifica --skipConfirm
|
|
112
|
+
if (!flags.skipConfirm) {
|
|
113
|
+
const confirm = await inquirer.prompt([
|
|
26
114
|
{
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
message: "Select a project to create the Redis database in:",
|
|
32
|
-
name: "project",
|
|
33
|
-
type: "list",
|
|
115
|
+
type: 'confirm',
|
|
116
|
+
name: 'proceed',
|
|
117
|
+
message: 'Do you want to create this Redis instance?',
|
|
118
|
+
default: false,
|
|
34
119
|
},
|
|
35
120
|
]);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
type: "input",
|
|
121
|
+
if (!confirm.proceed) {
|
|
122
|
+
this.error(chalk.yellow("Redis creation cancelled."));
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
console.log(JSON.stringify({
|
|
128
|
+
name,
|
|
129
|
+
description,
|
|
130
|
+
databasePassword,
|
|
131
|
+
dockerImage,
|
|
132
|
+
appName,
|
|
133
|
+
projectId,
|
|
134
|
+
}, null, 2));
|
|
135
|
+
const response = await axios.post(`${auth.url}/api/trpc/redis.create`, {
|
|
136
|
+
json: {
|
|
137
|
+
name,
|
|
138
|
+
description,
|
|
139
|
+
databasePassword,
|
|
140
|
+
dockerImage,
|
|
141
|
+
appName,
|
|
142
|
+
projectId,
|
|
59
143
|
},
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
message: "Enter the App name:",
|
|
65
|
-
name: "appName",
|
|
66
|
-
type: "input",
|
|
67
|
-
validate: (input) => (input ? true : "App name is required"),
|
|
144
|
+
}, {
|
|
145
|
+
headers: {
|
|
146
|
+
Authorization: `Bearer ${auth.token}`,
|
|
147
|
+
"Content-Type": "application/json",
|
|
68
148
|
},
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
json: {
|
|
73
|
-
...dbDetails,
|
|
74
|
-
appName: appName.appName,
|
|
75
|
-
projectId: project.projectId,
|
|
76
|
-
},
|
|
77
|
-
}, {
|
|
78
|
-
headers: {
|
|
79
|
-
Authorization: `Bearer ${auth.token}`,
|
|
80
|
-
"Content-Type": "application/json",
|
|
81
|
-
},
|
|
82
|
-
});
|
|
83
|
-
if (!response.data.result.data.json) {
|
|
84
|
-
this.error(chalk.red("Error creating Redis database"));
|
|
85
|
-
}
|
|
86
|
-
this.log(chalk.green(`Redis database '${dbDetails.name}' created successfully.`));
|
|
87
|
-
}
|
|
88
|
-
catch (error) {
|
|
89
|
-
this.error(
|
|
90
|
-
// @ts-ignore
|
|
91
|
-
chalk.red(`Failed to create Redis database: ${error.message}`));
|
|
149
|
+
});
|
|
150
|
+
if (!response.data.result.data.json) {
|
|
151
|
+
this.error(chalk.red("Error creating Redis instance", response.data.result.data.json));
|
|
92
152
|
}
|
|
153
|
+
this.log(chalk.green(`Redis instance '${name}' created successfully.`));
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
this.error(chalk.red(`Error creating Redis instance: ${error.message}`));
|
|
93
157
|
}
|
|
94
158
|
}
|
|
95
159
|
}
|
|
@@ -4,6 +4,8 @@ export default class DatabaseRedisDelete extends Command {
|
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|
|
6
6
|
projectId: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
7
|
+
redisId: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
8
|
+
skipConfirm: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
7
9
|
};
|
|
8
10
|
run(): Promise<void>;
|
|
9
11
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Command, Flags } from "@oclif/core";
|
|
2
|
-
import axios from "axios";
|
|
3
|
-
import chalk from "chalk";
|
|
4
|
-
import inquirer from "inquirer";
|
|
5
2
|
import { readAuthConfig } from "../../../utils/utils.js";
|
|
3
|
+
import chalk from "chalk";
|
|
6
4
|
import { getProject, getProjects } from "../../../utils/shared.js";
|
|
5
|
+
import inquirer from "inquirer";
|
|
6
|
+
import axios from "axios";
|
|
7
7
|
export default class DatabaseRedisDelete extends Command {
|
|
8
|
-
static description = "Delete
|
|
8
|
+
static description = "Delete a Redis instance from a project.";
|
|
9
9
|
static examples = [
|
|
10
10
|
"$ <%= config.bin %> redis delete",
|
|
11
11
|
"$ <%= config.bin %> redis delete -p <projectId>",
|
|
@@ -16,63 +16,75 @@ export default class DatabaseRedisDelete extends Command {
|
|
|
16
16
|
description: "ID of the project",
|
|
17
17
|
required: false,
|
|
18
18
|
}),
|
|
19
|
+
redisId: Flags.string({
|
|
20
|
+
char: "r",
|
|
21
|
+
description: "ID of the Redis instance to delete",
|
|
22
|
+
required: false,
|
|
23
|
+
}),
|
|
24
|
+
skipConfirm: Flags.boolean({
|
|
25
|
+
char: "y",
|
|
26
|
+
description: "Skip confirmation prompt",
|
|
27
|
+
default: false,
|
|
28
|
+
}),
|
|
19
29
|
};
|
|
20
30
|
async run() {
|
|
21
31
|
const auth = await readAuthConfig(this);
|
|
22
32
|
const { flags } = await this.parse(DatabaseRedisDelete);
|
|
23
|
-
let { projectId } = flags;
|
|
24
|
-
|
|
33
|
+
let { projectId, redisId } = flags;
|
|
34
|
+
// Modo interactivo si no se proporcionan los flags necesarios
|
|
35
|
+
if (!projectId || !redisId) {
|
|
25
36
|
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
|
26
37
|
const projects = await getProjects(auth, this);
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
|
|
38
|
+
if (!projectId) {
|
|
39
|
+
const answers = await inquirer.prompt([
|
|
40
|
+
{
|
|
41
|
+
choices: projects.map((project) => ({
|
|
42
|
+
name: project.name,
|
|
43
|
+
value: project.projectId,
|
|
44
|
+
})),
|
|
45
|
+
message: "Select a project to delete the Redis instance from:",
|
|
46
|
+
name: "selectedProject",
|
|
47
|
+
type: "list",
|
|
48
|
+
},
|
|
49
|
+
]);
|
|
50
|
+
projectId = answers.selectedProject;
|
|
30
51
|
}
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
name: project.name,
|
|
35
|
-
value: project.projectId,
|
|
36
|
-
})),
|
|
37
|
-
message: "Select a project to delete the redis database from:",
|
|
38
|
-
name: "selectedProject",
|
|
39
|
-
type: "list",
|
|
40
|
-
},
|
|
41
|
-
]);
|
|
42
|
-
projectId = answers.selectedProject;
|
|
43
|
-
}
|
|
44
|
-
try {
|
|
45
|
-
const project = await getProject(projectId, auth, this);
|
|
46
|
-
if (!project.redis || project.redis.length === 0) {
|
|
47
|
-
this.log(chalk.yellow("No redis databases found in this project."));
|
|
48
|
-
return;
|
|
52
|
+
const projectSelected = await getProject(projectId, auth, this);
|
|
53
|
+
if (!projectSelected.redis || projectSelected.redis.length === 0) {
|
|
54
|
+
this.error(chalk.yellow("No Redis instances found in this project."));
|
|
49
55
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
if (!redisId) {
|
|
57
|
+
const dbAnswers = await inquirer.prompt([
|
|
58
|
+
{
|
|
59
|
+
// @ts-ignore
|
|
60
|
+
choices: projectSelected.redis.map((db) => ({
|
|
61
|
+
name: db.name,
|
|
62
|
+
value: db.redisId,
|
|
63
|
+
})),
|
|
64
|
+
message: "Select the Redis instance to delete:",
|
|
65
|
+
name: "selectedDb",
|
|
66
|
+
type: "list",
|
|
67
|
+
},
|
|
68
|
+
]);
|
|
69
|
+
redisId = dbAnswers.selectedDb;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// Confirmar si no se especifica --skipConfirm
|
|
73
|
+
if (!flags.skipConfirm) {
|
|
63
74
|
const confirmAnswers = await inquirer.prompt([
|
|
64
75
|
{
|
|
65
76
|
default: false,
|
|
66
|
-
message: "Are you sure you want to delete this
|
|
77
|
+
message: "Are you sure you want to delete this Redis instance?",
|
|
67
78
|
name: "confirmDelete",
|
|
68
79
|
type: "confirm",
|
|
69
80
|
},
|
|
70
81
|
]);
|
|
71
82
|
if (!confirmAnswers.confirmDelete) {
|
|
72
|
-
this.
|
|
73
|
-
return;
|
|
83
|
+
this.error(chalk.yellow("Redis deletion cancelled."));
|
|
74
84
|
}
|
|
75
|
-
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
const response = await axios.post(`${auth.url}/api/trpc/redis.remove`, {
|
|
76
88
|
json: {
|
|
77
89
|
redisId,
|
|
78
90
|
},
|
|
@@ -82,15 +94,13 @@ export default class DatabaseRedisDelete extends Command {
|
|
|
82
94
|
"Content-Type": "application/json",
|
|
83
95
|
},
|
|
84
96
|
});
|
|
85
|
-
if (!
|
|
86
|
-
this.error(chalk.red("Error deleting
|
|
97
|
+
if (!response.data.result.data.json) {
|
|
98
|
+
this.error(chalk.red("Error deleting Redis instance"));
|
|
87
99
|
}
|
|
88
|
-
this.log(chalk.green("Redis
|
|
100
|
+
this.log(chalk.green("Redis instance deleted successfully."));
|
|
89
101
|
}
|
|
90
102
|
catch (error) {
|
|
91
|
-
this.error(
|
|
92
|
-
// @ts-expect-error - TS2339: Property 'data' does not exist on type 'AxiosError<any>'.
|
|
93
|
-
chalk.red(`Failed to delete redis database: ${error.message}`));
|
|
103
|
+
this.error(chalk.red(`Error deleting Redis instance: ${error.message}`));
|
|
94
104
|
}
|
|
95
105
|
}
|
|
96
106
|
}
|
|
@@ -2,5 +2,10 @@ import { Command } from "@oclif/core";
|
|
|
2
2
|
export default class DatabaseRedisDeploy extends Command {
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
|
+
static flags: {
|
|
6
|
+
projectId: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
7
|
+
redisId: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
8
|
+
skipConfirm: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
9
|
+
};
|
|
5
10
|
run(): Promise<void>;
|
|
6
11
|
}
|