@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.
Files changed (57) hide show
  1. package/LICENSE.md +21 -0
  2. package/dist/commands/app/create.d.ts +4 -0
  3. package/dist/commands/app/create.js +87 -37
  4. package/dist/commands/app/delete.d.ts +2 -0
  5. package/dist/commands/app/delete.js +50 -28
  6. package/dist/commands/app/deploy.d.ts +5 -0
  7. package/dist/commands/app/deploy.js +93 -55
  8. package/dist/commands/app/stop.d.ts +5 -0
  9. package/dist/commands/app/stop.js +87 -54
  10. package/dist/commands/database/mariadb/create.d.ts +9 -0
  11. package/dist/commands/database/mariadb/create.js +160 -66
  12. package/dist/commands/database/mariadb/delete.d.ts +2 -0
  13. package/dist/commands/database/mariadb/delete.js +56 -47
  14. package/dist/commands/database/mariadb/deploy.d.ts +5 -0
  15. package/dist/commands/database/mariadb/deploy.js +88 -54
  16. package/dist/commands/database/mariadb/stop.d.ts +5 -0
  17. package/dist/commands/database/mariadb/stop.js +88 -54
  18. package/dist/commands/database/mongo/create.d.ts +8 -0
  19. package/dist/commands/database/mongo/create.js +145 -76
  20. package/dist/commands/database/mongo/delete.d.ts +2 -0
  21. package/dist/commands/database/mongo/delete.js +56 -45
  22. package/dist/commands/database/mongo/deploy.d.ts +5 -0
  23. package/dist/commands/database/mongo/deploy.js +88 -54
  24. package/dist/commands/database/mongo/stop.d.ts +5 -0
  25. package/dist/commands/database/mongo/stop.js +88 -54
  26. package/dist/commands/database/mysql/create.d.ts +9 -0
  27. package/dist/commands/database/mysql/create.js +168 -81
  28. package/dist/commands/database/mysql/delete.d.ts +2 -0
  29. package/dist/commands/database/mysql/delete.js +56 -47
  30. package/dist/commands/database/mysql/deploy.js +70 -53
  31. package/dist/commands/database/mysql/stop.js +70 -53
  32. package/dist/commands/database/postgres/create.d.ts +8 -0
  33. package/dist/commands/database/postgres/create.js +155 -76
  34. package/dist/commands/database/postgres/delete.d.ts +2 -0
  35. package/dist/commands/database/postgres/delete.js +56 -44
  36. package/dist/commands/database/postgres/deploy.d.ts +5 -0
  37. package/dist/commands/database/postgres/deploy.js +90 -56
  38. package/dist/commands/database/postgres/stop.d.ts +5 -0
  39. package/dist/commands/database/postgres/stop.js +91 -57
  40. package/dist/commands/database/redis/create.d.ts +6 -0
  41. package/dist/commands/database/redis/create.js +129 -65
  42. package/dist/commands/database/redis/delete.d.ts +2 -0
  43. package/dist/commands/database/redis/delete.js +60 -50
  44. package/dist/commands/database/redis/deploy.d.ts +5 -0
  45. package/dist/commands/database/redis/deploy.js +90 -56
  46. package/dist/commands/database/redis/stop.d.ts +5 -0
  47. package/dist/commands/database/redis/stop.js +91 -57
  48. package/dist/commands/env/pull.d.ts +10 -0
  49. package/dist/commands/env/pull.js +68 -0
  50. package/dist/commands/env/push.d.ts +10 -0
  51. package/dist/commands/env/push.js +106 -0
  52. package/dist/commands/project/create.d.ts +2 -1
  53. package/dist/commands/project/create.js +53 -34
  54. package/dist/utils/utils.js +9 -2
  55. package/oclif.manifest.json +895 -110
  56. package/package.json +3 -2
  57. package/{README.md → readme.md} +16 -1
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Mauricio Siu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -8,6 +8,10 @@ export default class AppCreate extends Command {
8
8
  static examples: string[];
9
9
  static flags: {
10
10
  projectId: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
11
+ name: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
12
+ description: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
13
+ appName: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
14
+ skipConfirm: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
11
15
  };
12
16
  run(): Promise<void>;
13
17
  }
@@ -14,53 +14,100 @@ export default class AppCreate extends Command {
14
14
  description: "ID of the project",
15
15
  required: false,
16
16
  }),
17
+ name: Flags.string({
18
+ char: "n",
19
+ description: "Application name",
20
+ required: false,
21
+ }),
22
+ description: Flags.string({
23
+ char: "d",
24
+ description: "Application description",
25
+ required: false,
26
+ }),
27
+ appName: Flags.string({
28
+ description: "Docker app name",
29
+ required: false,
30
+ }),
31
+ skipConfirm: Flags.boolean({
32
+ char: "y",
33
+ description: "Skip confirmation prompt",
34
+ default: false,
35
+ }),
17
36
  };
18
37
  async run() {
19
38
  const auth = await readAuthConfig(this);
20
39
  const { flags } = await this.parse(AppCreate);
21
- let { projectId } = flags;
22
- if (!projectId) {
40
+ let { projectId, name, description, appName } = flags;
41
+ // Modo interactivo si no se proporcionan los flags necesarios
42
+ if (!projectId || !name || !appName) {
23
43
  console.log(chalk.blue.bold("\n Listing all Projects \n"));
24
44
  const projects = await getProjects(auth, this);
25
- const { project } = await inquirer.prompt([
26
- {
27
- choices: projects.map((project) => ({
28
- name: project.name,
29
- value: project,
30
- })),
31
- message: "Select a project to create the application in:",
32
- name: "project",
33
- type: "list",
34
- },
35
- ]);
36
- projectId = project.projectId;
37
- const appDetails = await inquirer.prompt([
38
- {
39
- message: "Enter the application name:",
40
- name: "name",
41
- type: "input",
42
- validate: (input) => (input ? true : "Application name is required"),
43
- },
44
- {
45
- message: "Enter the application description (optional):",
46
- name: "appDescription",
47
- type: "input",
48
- },
49
- ]);
50
- const appName = await inquirer.prompt([
45
+ if (!projectId) {
46
+ const { project } = await inquirer.prompt([
47
+ {
48
+ choices: projects.map((project) => ({
49
+ name: project.name,
50
+ value: project,
51
+ })),
52
+ message: "Select a project to create the application in:",
53
+ name: "project",
54
+ type: "list",
55
+ },
56
+ ]);
57
+ projectId = project.projectId;
58
+ }
59
+ if (!name || !appName) {
60
+ const appDetails = await inquirer.prompt([
61
+ {
62
+ message: "Enter the application name:",
63
+ name: "name",
64
+ type: "input",
65
+ validate: (input) => (input ? true : "Application name is required"),
66
+ default: name,
67
+ },
68
+ {
69
+ message: "Enter the application description (optional):",
70
+ name: "appDescription",
71
+ type: "input",
72
+ default: description,
73
+ },
74
+ ]);
75
+ name = appDetails.name;
76
+ description = appDetails.appDescription;
77
+ const appNamePrompt = await inquirer.prompt([
78
+ {
79
+ default: appName || `${slugify(name)}`,
80
+ message: "Enter the App name:",
81
+ name: "appName",
82
+ type: "input",
83
+ validate: (input) => (input ? true : "App name is required"),
84
+ },
85
+ ]);
86
+ appName = appNamePrompt.appName;
87
+ }
88
+ }
89
+ // Confirmar si no se especifica --skipConfirm
90
+ if (!flags.skipConfirm) {
91
+ const confirm = await inquirer.prompt([
51
92
  {
52
- default: `${slugify(project.name)}-${appDetails.name}`,
53
- message: "Enter the App name: (optional):",
54
- name: "appName",
55
- type: "input",
56
- validate: (input) => (input ? true : "App name is required"),
93
+ type: 'confirm',
94
+ name: 'proceed',
95
+ message: 'Do you want to create this application?',
96
+ default: false,
57
97
  },
58
98
  ]);
99
+ if (!confirm.proceed) {
100
+ this.error(chalk.yellow("Application creation cancelled."));
101
+ return;
102
+ }
103
+ }
104
+ try {
59
105
  const response = await axios.post(`${auth.url}/api/trpc/application.create`, {
60
106
  json: {
61
- ...appDetails,
62
- appName: appName.appName,
63
- projectId: project.projectId,
107
+ name,
108
+ appDescription: description,
109
+ appName,
110
+ projectId,
64
111
  },
65
112
  }, {
66
113
  headers: {
@@ -71,7 +118,10 @@ export default class AppCreate extends Command {
71
118
  if (response.status !== 200) {
72
119
  this.error(chalk.red("Error creating application"));
73
120
  }
74
- this.log(chalk.green(`Application '${appDetails.name}' created successfully.`));
121
+ this.log(chalk.green(`Application '${name}' created successfully.`));
122
+ }
123
+ catch (error) {
124
+ this.error(chalk.red(`Error creating application: ${error.message}`));
75
125
  }
76
126
  }
77
127
  }
@@ -4,6 +4,8 @@ export default class AppDelete 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
+ applicationId: 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
  }
@@ -16,44 +16,61 @@ export default class AppDelete extends Command {
16
16
  description: "ID of the project",
17
17
  required: false,
18
18
  }),
19
+ applicationId: Flags.string({
20
+ char: 'a',
21
+ description: 'ID of the application 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(AppDelete);
23
- let { projectId } = flags;
24
- if (!projectId) {
33
+ let { projectId, applicationId } = flags;
34
+ // Modo interactivo si no se proporcionan los flags necesarios
35
+ if (!projectId || !applicationId) {
25
36
  console.log(chalk.blue.bold("\n Listing all Projects \n"));
26
37
  const projects = await getProjects(auth, this);
27
- const { project } = await inquirer.prompt([
28
- {
29
- choices: projects.map((project) => ({
30
- name: project.name,
31
- value: project,
32
- })),
33
- message: "Select a project to create the application in:",
34
- name: "project",
35
- type: "list",
36
- },
37
- ]);
38
- projectId = project.projectId;
38
+ if (!projectId) {
39
+ const { project } = await inquirer.prompt([
40
+ {
41
+ choices: projects.map((project) => ({
42
+ name: project.name,
43
+ value: project,
44
+ })),
45
+ message: "Select a project to delete the application from:",
46
+ name: "project",
47
+ type: "list",
48
+ },
49
+ ]);
50
+ projectId = project.projectId;
51
+ }
39
52
  const projectSelected = await getProject(projectId, auth, this);
40
53
  if (projectSelected.applications.length === 0) {
41
54
  this.error(chalk.yellow("No applications found in this project."));
42
55
  }
43
- const appAnswers = await inquirer.prompt([
44
- {
45
- // @ts-ignore
46
- choices: projectSelected.applications.map((app) => ({
47
- name: app.name,
48
- value: app.applicationId,
49
- })),
50
- message: "Select the application to delete:",
51
- name: "selectedApp",
52
- type: "list",
53
- },
54
- ]);
55
- const applicationId = appAnswers.selectedApp;
56
- // // Confirmar eliminación
56
+ if (!applicationId) {
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
+ applicationId = appAnswers.selectedApp;
70
+ }
71
+ }
72
+ // Confirmar si no se especifica --skipConfirm
73
+ if (!flags.skipConfirm) {
57
74
  const confirmAnswers = await inquirer.prompt([
58
75
  {
59
76
  default: false,
@@ -65,6 +82,8 @@ export default class AppDelete extends Command {
65
82
  if (!confirmAnswers.confirmDelete) {
66
83
  this.error(chalk.yellow("Application deletion cancelled."));
67
84
  }
85
+ }
86
+ try {
68
87
  const deleteResponse = await axios.post(`${auth.url}/api/trpc/application.delete`, {
69
88
  json: {
70
89
  applicationId,
@@ -80,5 +99,8 @@ export default class AppDelete extends Command {
80
99
  }
81
100
  this.log(chalk.green("Application deleted successfully."));
82
101
  }
102
+ catch (error) {
103
+ this.error(chalk.red(`Failed to delete application: ${error.message}`));
104
+ }
83
105
  }
84
106
  }
@@ -2,5 +2,10 @@ import { Command } from "@oclif/core";
2
2
  export default class AppDeploy extends Command {
3
3
  static description: string;
4
4
  static examples: string[];
5
+ static flags: {
6
+ applicationId: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
7
+ projectId: 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
  }
@@ -1,4 +1,4 @@
1
- import { Command } from "@oclif/core";
1
+ import { Command, Flags } from "@oclif/core";
2
2
  import { readAuthConfig } from "../../utils/utils.js";
3
3
  import chalk from "chalk";
4
4
  import { getProject, getProjects } from "../../utils/shared.js";
@@ -6,64 +6,102 @@ import inquirer from "inquirer";
6
6
  import axios from "axios";
7
7
  export default class AppDeploy extends Command {
8
8
  static description = "Deploy an application to a project.";
9
- static examples = ["$ <%= config.bin %> app deploy"];
9
+ static examples = [
10
+ "$ <%= config.bin %> app deploy",
11
+ "$ <%= config.bin %> app deploy --applicationId myAppId",
12
+ "$ DOKPLOY_URL=xxx DOKPLOY_AUTH_TOKEN=xxx <%= config.bin %> app deploy --applicationId myAppId"
13
+ ];
14
+ static flags = {
15
+ applicationId: Flags.string({
16
+ char: 'a',
17
+ description: 'ID of the application to deploy',
18
+ required: false,
19
+ }),
20
+ projectId: Flags.string({
21
+ char: 'p',
22
+ description: 'ID of the project',
23
+ required: false,
24
+ }),
25
+ skipConfirm: Flags.boolean({
26
+ char: 'y',
27
+ description: 'Skip confirmation prompt',
28
+ default: false,
29
+ })
30
+ };
10
31
  async run() {
11
32
  const auth = await readAuthConfig(this);
12
- console.log(chalk.blue.bold("\n Listing all Projects \n"));
13
- const projects = await getProjects(auth, this);
14
- const { project } = await inquirer.prompt([
15
- {
16
- choices: projects.map((project) => ({
17
- name: project.name,
18
- value: project,
19
- })),
20
- message: "Select a project to deploy the application in:",
21
- name: "project",
22
- type: "list",
23
- },
24
- ]);
25
- const projectId = project.projectId;
26
- const projectSelected = await getProject(projectId, auth, this);
27
- if (projectSelected.applications.length === 0) {
28
- this.error(chalk.yellow("No applications found in this project."));
33
+ const { flags } = await this.parse(AppDeploy);
34
+ let { projectId, applicationId } = flags;
35
+ // Modo interactivo si no se proporcionan los flags necesarios
36
+ if (!projectId || !applicationId) {
37
+ console.log(chalk.blue.bold("\n Listing all Projects \n"));
38
+ const projects = await getProjects(auth, this);
39
+ if (!projectId) {
40
+ const { project } = await inquirer.prompt([
41
+ {
42
+ choices: projects.map((project) => ({
43
+ name: project.name,
44
+ value: project,
45
+ })),
46
+ message: "Select a project to deploy the application from:",
47
+ name: "project",
48
+ type: "list",
49
+ },
50
+ ]);
51
+ projectId = project.projectId;
52
+ }
53
+ const projectSelected = await getProject(projectId, auth, this);
54
+ if (projectSelected.applications.length === 0) {
55
+ this.error(chalk.yellow("No applications found in this project."));
56
+ }
57
+ if (!applicationId) {
58
+ const appAnswers = await inquirer.prompt([
59
+ {
60
+ // @ts-ignore
61
+ choices: projectSelected.applications.map((app) => ({
62
+ name: app.name,
63
+ value: app.applicationId,
64
+ })),
65
+ message: "Select the application to deploy:",
66
+ name: "selectedApp",
67
+ type: "list",
68
+ },
69
+ ]);
70
+ applicationId = appAnswers.selectedApp;
71
+ }
29
72
  }
30
- const appAnswers = await inquirer.prompt([
31
- {
32
- // @ts-ignore
33
- choices: projectSelected.applications.map((app) => ({
34
- name: app.name,
35
- value: app.applicationId,
36
- })),
37
- message: "Select the application to deploy:",
38
- name: "selectedApp",
39
- type: "list",
40
- },
41
- ]);
42
- const applicationId = appAnswers.selectedApp;
43
- const confirmAnswers = await inquirer.prompt([
44
- {
45
- default: false,
46
- message: "Are you sure you want to deploy this application?",
47
- name: "confirmDelete",
48
- type: "confirm",
49
- },
50
- ]);
51
- if (!confirmAnswers.confirmDelete) {
52
- this.error(chalk.yellow("Application deployment cancelled."));
73
+ // Confirmar si no se especifica --skipConfirm
74
+ if (!flags.skipConfirm) {
75
+ const confirmAnswers = await inquirer.prompt([
76
+ {
77
+ default: false,
78
+ message: "Are you sure you want to deploy this application?",
79
+ name: "confirmDelete",
80
+ type: "confirm",
81
+ },
82
+ ]);
83
+ if (!confirmAnswers.confirmDelete) {
84
+ this.error(chalk.yellow("Application deployment cancelled."));
85
+ }
53
86
  }
54
- const response = await axios.post(`${auth.url}/api/trpc/application.deploy`, {
55
- json: {
56
- applicationId,
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 deploying application"));
87
+ try {
88
+ const response = await axios.post(`${auth.url}/api/trpc/application.deploy`, {
89
+ json: {
90
+ applicationId,
91
+ },
92
+ }, {
93
+ headers: {
94
+ Authorization: `Bearer ${auth.token}`,
95
+ "Content-Type": "application/json",
96
+ },
97
+ });
98
+ if (response.status !== 200) {
99
+ this.error(chalk.red("Error deploying application"));
100
+ }
101
+ this.log(chalk.green("Application deploy successful."));
102
+ }
103
+ catch (error) {
104
+ this.error(chalk.red(`Error deploying application: ${error.message}`));
66
105
  }
67
- this.log(chalk.green("Application deploy successful."));
68
106
  }
69
107
  }
@@ -2,5 +2,10 @@ import { Command } from "@oclif/core";
2
2
  export default class AppStop 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
+ applicationId: 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
  }
@@ -1,4 +1,4 @@
1
- import { Command } from "@oclif/core";
1
+ import { Command, Flags } from "@oclif/core";
2
2
  import { readAuthConfig } from "../../utils/utils.js";
3
3
  import chalk from "chalk";
4
4
  import inquirer from "inquirer";
@@ -7,63 +7,96 @@ import axios from "axios";
7
7
  export default class AppStop extends Command {
8
8
  static description = "Stop an application from a project.";
9
9
  static examples = ["$ <%= config.bin %> app stop"];
10
+ static flags = {
11
+ projectId: Flags.string({
12
+ char: 'p',
13
+ description: 'ID of the project',
14
+ required: false,
15
+ }),
16
+ applicationId: Flags.string({
17
+ char: 'a',
18
+ description: 'ID of the application 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
- console.log(chalk.blue.bold("\n Listing all Projects \n"));
13
- const projects = await getProjects(auth, this);
14
- const { project } = await inquirer.prompt([
15
- {
16
- choices: projects.map((project) => ({
17
- name: project.name,
18
- value: project,
19
- })),
20
- message: "Select a project to stop the application in:",
21
- name: "project",
22
- type: "list",
23
- },
24
- ]);
25
- const projectId = project.projectId;
26
- const projectSelected = await getProject(projectId, auth, this);
27
- if (projectSelected.applications.length === 0) {
28
- this.error(chalk.yellow("No applications found in this project."));
29
+ const { flags } = await this.parse(AppStop);
30
+ let { projectId, applicationId } = flags;
31
+ // Modo interactivo si no se proporcionan los flags necesarios
32
+ if (!projectId || !applicationId) {
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 application 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.applications.length === 0) {
51
+ this.error(chalk.yellow("No applications found in this project."));
52
+ }
53
+ if (!applicationId) {
54
+ const appAnswers = await inquirer.prompt([
55
+ {
56
+ choices: projectSelected.applications.map((app) => ({
57
+ name: app.name,
58
+ value: app.applicationId,
59
+ })),
60
+ message: "Select the application to stop:",
61
+ name: "selectedApp",
62
+ type: "list",
63
+ },
64
+ ]);
65
+ applicationId = appAnswers.selectedApp;
66
+ }
29
67
  }
30
- const appAnswers = await inquirer.prompt([
31
- {
32
- // @ts-ignore
33
- choices: projectSelected.applications.map((app) => ({
34
- name: app.name,
35
- value: app.applicationId,
36
- })),
37
- message: "Select the application to stop:",
38
- name: "selectedApp",
39
- type: "list",
40
- },
41
- ]);
42
- const applicationId = appAnswers.selectedApp;
43
- const confirmAnswers = await inquirer.prompt([
44
- {
45
- default: false,
46
- message: "Are you sure you want to stop this application?",
47
- name: "confirmDelete",
48
- type: "confirm",
49
- },
50
- ]);
51
- if (!confirmAnswers.confirmDelete) {
52
- this.error(chalk.yellow("Application stop cancelled."));
68
+ // Confirmar si no se especifica --skipConfirm
69
+ if (!flags.skipConfirm) {
70
+ const confirmAnswers = await inquirer.prompt([
71
+ {
72
+ default: false,
73
+ message: "Are you sure you want to stop this application?",
74
+ name: "confirmDelete",
75
+ type: "confirm",
76
+ },
77
+ ]);
78
+ if (!confirmAnswers.confirmDelete) {
79
+ this.error(chalk.yellow("Application stop cancelled."));
80
+ }
53
81
  }
54
- const response = await axios.post(`${auth.url}/api/trpc/application.stop`, {
55
- json: {
56
- applicationId,
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 application"));
82
+ try {
83
+ const response = await axios.post(`${auth.url}/api/trpc/application.stop`, {
84
+ json: {
85
+ applicationId,
86
+ },
87
+ }, {
88
+ headers: {
89
+ Authorization: `Bearer ${auth.token}`,
90
+ "Content-Type": "application/json",
91
+ },
92
+ });
93
+ if (response.status !== 200) {
94
+ this.error(chalk.red("Error stopping application"));
95
+ }
96
+ this.log(chalk.green("Application stop successful."));
97
+ }
98
+ catch (error) {
99
+ this.error(chalk.red(`Error stopping application: ${error.message}`));
66
100
  }
67
- this.log(chalk.green("Application stop successful."));
68
101
  }
69
102
  }