Skip to content

Commit 21dd3f0

Browse files
authored
Merge pull request #6 from Dokploy/2-make-the-cli-work-on-ci
2 parents 7cb5369 + 6d186d5 commit 21dd3f0

28 files changed

+2428
-1549
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@dokploy/cli",
33
"description": "A CLI to manage dokploy server remotely",
4-
"version": "v0.2.4",
4+
"version": "v0.2.6",
55
"author": "Mauricio Siu",
66
"licenses": [{
77
"type": "MIT",

src/commands/app/create.ts

Lines changed: 89 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -22,65 +22,112 @@ export default class AppCreate extends Command {
2222
description: "ID of the project",
2323
required: false,
2424
}),
25+
name: Flags.string({
26+
char: "n",
27+
description: "Application name",
28+
required: false,
29+
}),
30+
description: Flags.string({
31+
char: "d",
32+
description: "Application description",
33+
required: false,
34+
}),
35+
appName: Flags.string({
36+
description: "Docker app name",
37+
required: false,
38+
}),
39+
skipConfirm: Flags.boolean({
40+
char: "y",
41+
description: "Skip confirmation prompt",
42+
default: false,
43+
}),
2544
};
2645

2746
public async run(): Promise<void> {
2847
const auth = await readAuthConfig(this);
29-
3048
const { flags } = await this.parse(AppCreate);
49+
let { projectId, name, description, appName } = flags;
3150

32-
let { projectId } = flags;
33-
34-
if (!projectId) {
51+
// Modo interactivo si no se proporcionan los flags necesarios
52+
if (!projectId || !name || !appName) {
3553
console.log(chalk.blue.bold("\n Listing all Projects \n"));
36-
3754
const projects = await getProjects(auth, this);
3855

39-
const { project } = await inquirer.prompt<Answers>([
40-
{
41-
choices: projects.map((project) => ({
42-
name: project.name,
43-
value: project,
44-
})),
45-
message: "Select a project to create the application in:",
46-
name: "project",
47-
type: "list",
48-
},
49-
]);
56+
if (!projectId) {
57+
const { project } = await inquirer.prompt<Answers>([
58+
{
59+
choices: projects.map((project) => ({
60+
name: project.name,
61+
value: project,
62+
})),
63+
message: "Select a project to create the application in:",
64+
name: "project",
65+
type: "list",
66+
},
67+
]);
68+
projectId = project.projectId;
69+
}
5070

51-
projectId = project.projectId;
71+
if (!name || !appName) {
72+
const appDetails = await inquirer.prompt([
73+
{
74+
message: "Enter the application name:",
75+
name: "name",
76+
type: "input",
77+
validate: (input) => (input ? true : "Application name is required"),
78+
default: name,
79+
},
80+
{
81+
message: "Enter the application description (optional):",
82+
name: "appDescription",
83+
type: "input",
84+
default: description,
85+
},
86+
]);
87+
88+
name = appDetails.name;
89+
description = appDetails.appDescription;
90+
91+
const appNamePrompt = await inquirer.prompt([
92+
{
93+
default: appName || `${slugify(name)}`,
94+
message: "Enter the App name:",
95+
name: "appName",
96+
type: "input",
97+
validate: (input) => (input ? true : "App name is required"),
98+
},
99+
]);
52100

53-
const appDetails = await inquirer.prompt([
54-
{
55-
message: "Enter the application name:",
56-
name: "name",
57-
type: "input",
58-
validate: (input) => (input ? true : "Application name is required"),
59-
},
60-
{
61-
message: "Enter the application description (optional):",
62-
name: "appDescription",
63-
type: "input",
64-
},
65-
]);
101+
appName = appNamePrompt.appName;
102+
}
103+
}
66104

67-
const appName = await inquirer.prompt([
105+
// Confirmar si no se especifica --skipConfirm
106+
if (!flags.skipConfirm) {
107+
const confirm = await inquirer.prompt([
68108
{
69-
default: `${slugify(project.name)}-${appDetails.name}`,
70-
message: "Enter the App name: (optional):",
71-
name: "appName",
72-
type: "input",
73-
validate: (input) => (input ? true : "App name is required"),
109+
type: 'confirm',
110+
name: 'proceed',
111+
message: 'Do you want to create this application?',
112+
default: false,
74113
},
75114
]);
76115

116+
if (!confirm.proceed) {
117+
this.error(chalk.yellow("Application creation cancelled."));
118+
return;
119+
}
120+
}
121+
122+
try {
77123
const response = await axios.post(
78124
`${auth.url}/api/trpc/application.create`,
79125
{
80126
json: {
81-
...appDetails,
82-
appName: appName.appName,
83-
projectId: project.projectId,
127+
name,
128+
appDescription: description,
129+
appName,
130+
projectId,
84131
},
85132
},
86133
{
@@ -95,9 +142,9 @@ export default class AppCreate extends Command {
95142
this.error(chalk.red("Error creating application"));
96143
}
97144

98-
this.log(
99-
chalk.green(`Application '${appDetails.name}' created successfully.`),
100-
);
145+
this.log(chalk.green(`Application '${name}' created successfully.`));
146+
} catch (error: any) {
147+
this.error(chalk.red(`Error creating application: ${error.message}`));
101148
}
102149
}
103150
}

src/commands/app/delete.ts

Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,55 +21,68 @@ export default class AppDelete extends Command {
2121
description: "ID of the project",
2222
required: false,
2323
}),
24+
applicationId: Flags.string({
25+
char: 'a',
26+
description: 'ID of the application to delete',
27+
required: false,
28+
}),
29+
skipConfirm: Flags.boolean({
30+
char: 'y',
31+
description: 'Skip confirmation prompt',
32+
default: false,
33+
})
2434
};
2535

2636
public async run(): Promise<void> {
2737
const auth = await readAuthConfig(this);
28-
2938
const { flags } = await this.parse(AppDelete);
39+
let { projectId, applicationId } = flags;
3040

31-
let { projectId } = flags;
32-
33-
if (!projectId) {
41+
// Modo interactivo si no se proporcionan los flags necesarios
42+
if (!projectId || !applicationId) {
3443
console.log(chalk.blue.bold("\n Listing all Projects \n"));
35-
3644
const projects = await getProjects(auth, this);
3745

38-
const { project } = await inquirer.prompt<Answers>([
39-
{
40-
choices: projects.map((project) => ({
41-
name: project.name,
42-
value: project,
43-
})),
44-
message: "Select a project to create the application in:",
45-
name: "project",
46-
type: "list",
47-
},
48-
]);
46+
if (!projectId) {
47+
const { project } = await inquirer.prompt<Answers>([
48+
{
49+
choices: projects.map((project) => ({
50+
name: project.name,
51+
value: project,
52+
})),
53+
message: "Select a project to delete the application from:",
54+
name: "project",
55+
type: "list",
56+
},
57+
]);
58+
projectId = project.projectId;
59+
}
4960

50-
projectId = project.projectId;
5161
const projectSelected = await getProject(projectId, auth, this);
5262

5363
if (projectSelected.applications.length === 0) {
5464
this.error(chalk.yellow("No applications found in this project."));
5565
}
5666

57-
const appAnswers = await inquirer.prompt([
58-
{
59-
// @ts-ignore
60-
choices: projectSelected.applications.map((app) => ({
61-
name: app.name,
62-
value: app.applicationId,
63-
})),
64-
message: "Select the application to delete:",
65-
name: "selectedApp",
66-
type: "list",
67-
},
68-
]);
69-
70-
const applicationId = appAnswers.selectedApp;
67+
if (!applicationId) {
68+
const appAnswers = await inquirer.prompt([
69+
{
70+
// @ts-ignore
71+
choices: projectSelected.applications.map((app) => ({
72+
name: app.name,
73+
value: app.applicationId,
74+
})),
75+
message: "Select the application to delete:",
76+
name: "selectedApp",
77+
type: "list",
78+
},
79+
]);
80+
applicationId = appAnswers.selectedApp;
81+
}
82+
}
7183

72-
// // Confirmar eliminación
84+
// Confirmar si no se especifica --skipConfirm
85+
if (!flags.skipConfirm) {
7386
const confirmAnswers = await inquirer.prompt([
7487
{
7588
default: false,
@@ -82,7 +95,9 @@ export default class AppDelete extends Command {
8295
if (!confirmAnswers.confirmDelete) {
8396
this.error(chalk.yellow("Application deletion cancelled."));
8497
}
98+
}
8599

100+
try {
86101
const deleteResponse = await axios.post(
87102
`${auth.url}/api/trpc/application.delete`,
88103
{
@@ -103,6 +118,8 @@ export default class AppDelete extends Command {
103118
}
104119

105120
this.log(chalk.green("Application deleted successfully."));
121+
} catch (error: any) {
122+
this.error(chalk.red(`Failed to delete application: ${error.message}`));
106123
}
107124
}
108125
}

0 commit comments

Comments
 (0)