Skip to content

Commit 3b12f55

Browse files
committed
feat: add stop command
1 parent e48c58c commit 3b12f55

File tree

5 files changed

+445
-0
lines changed

5 files changed

+445
-0
lines changed

src/commands/database/mariadb/stop.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { Command } from "@oclif/core";
2+
import chalk from "chalk";
3+
import inquirer from "inquirer";
4+
import axios from "axios";
5+
import { getProject, getProjects } from "../../../utils/shared.js";
6+
import { readAuthConfig } from "../../../utils/utils.js";
7+
import type { Answers } from "../../app/create.js";
8+
9+
export default class DatabaseMariadbStop extends Command {
10+
static description = "Stop an mariadb from a project.";
11+
12+
static examples = ["$ <%= config.bin %> mariadb stop"];
13+
14+
public async run(): Promise<void> {
15+
const auth = await readAuthConfig(this);
16+
17+
console.log(chalk.blue.bold("\n Listing all Projects \n"));
18+
19+
const projects = await getProjects(auth, this);
20+
21+
const { project } = await inquirer.prompt<Answers>([
22+
{
23+
choices: projects.map((project) => ({
24+
name: project.name,
25+
value: project,
26+
})),
27+
message: "Select a project to stop the mariadb in:",
28+
name: "project",
29+
type: "list",
30+
},
31+
]);
32+
33+
const projectId = project.projectId;
34+
35+
const projectSelected = await getProject(projectId, auth, this);
36+
37+
if (projectSelected.mariadb.length === 0) {
38+
this.error(chalk.yellow("No mariadb found in this project."));
39+
}
40+
41+
const appAnswers = await inquirer.prompt([
42+
{
43+
// @ts-ignore
44+
choices: projectSelected.mariadb.map((app) => ({
45+
name: app.name,
46+
value: app.mariadbId,
47+
})),
48+
message: "Select the mariadb to stop:",
49+
name: "selectedApp",
50+
type: "list",
51+
},
52+
]);
53+
54+
const mariadbId = appAnswers.selectedApp;
55+
56+
const confirmAnswers = await inquirer.prompt([
57+
{
58+
default: false,
59+
message: "Are you sure you want to stop this mariadb?",
60+
name: "confirmDelete",
61+
type: "confirm",
62+
},
63+
]);
64+
65+
if (!confirmAnswers.confirmDelete) {
66+
this.error(chalk.yellow("Mariadb stop cancelled."));
67+
}
68+
69+
const response = await axios.post(
70+
`${auth.url}/api/trpc/mariadb.stop`,
71+
{
72+
json: {
73+
mariadbId,
74+
},
75+
},
76+
{
77+
headers: {
78+
Authorization: `Bearer ${auth.token}`,
79+
"Content-Type": "application/json",
80+
},
81+
},
82+
);
83+
84+
if (response.status !== 200) {
85+
this.error(chalk.red("Error stopping mariadb"));
86+
}
87+
this.log(chalk.green("Mariadb stop successful."));
88+
}
89+
}

src/commands/database/mongo/stop.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { Command } from "@oclif/core";
2+
import chalk from "chalk";
3+
import inquirer from "inquirer";
4+
import axios from "axios";
5+
import { getProject, getProjects } from "../../../utils/shared.js";
6+
import { readAuthConfig } from "../../../utils/utils.js";
7+
import type { Answers } from "../../app/create.js";
8+
9+
export default class DatabaseMongoStop extends Command {
10+
static description = "Stop an mongo from a project.";
11+
12+
static examples = ["$ <%= config.bin %> mongo stop"];
13+
14+
public async run(): Promise<void> {
15+
const auth = await readAuthConfig(this);
16+
17+
console.log(chalk.blue.bold("\n Listing all Projects \n"));
18+
19+
const projects = await getProjects(auth, this);
20+
21+
const { project } = await inquirer.prompt<Answers>([
22+
{
23+
choices: projects.map((project) => ({
24+
name: project.name,
25+
value: project,
26+
})),
27+
message: "Select a project to stop the mongo in:",
28+
name: "project",
29+
type: "list",
30+
},
31+
]);
32+
33+
const projectId = project.projectId;
34+
35+
const projectSelected = await getProject(projectId, auth, this);
36+
37+
if (projectSelected.mongo.length === 0) {
38+
this.error(chalk.yellow("No mongo found in this project."));
39+
}
40+
41+
const appAnswers = await inquirer.prompt([
42+
{
43+
// @ts-ignore
44+
choices: projectSelected.mongo.map((app) => ({
45+
name: app.name,
46+
value: app.mongoId,
47+
})),
48+
message: "Select the mongo to stop:",
49+
name: "selectedApp",
50+
type: "list",
51+
},
52+
]);
53+
54+
const mongoId = appAnswers.selectedApp;
55+
56+
const confirmAnswers = await inquirer.prompt([
57+
{
58+
default: false,
59+
message: "Are you sure you want to stop this mongo?",
60+
name: "confirmDelete",
61+
type: "confirm",
62+
},
63+
]);
64+
65+
if (!confirmAnswers.confirmDelete) {
66+
this.error(chalk.yellow("mongo stop cancelled."));
67+
}
68+
69+
const response = await axios.post(
70+
`${auth.url}/api/trpc/mongo.stop`,
71+
{
72+
json: {
73+
mongoId,
74+
},
75+
},
76+
{
77+
headers: {
78+
Authorization: `Bearer ${auth.token}`,
79+
"Content-Type": "application/json",
80+
},
81+
},
82+
);
83+
84+
if (response.status !== 200) {
85+
this.error(chalk.red("Error stopping mongo"));
86+
}
87+
this.log(chalk.green("Mongo stop successful."));
88+
}
89+
}

src/commands/database/mysql/stop.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { Command } from "@oclif/core";
2+
import chalk from "chalk";
3+
import inquirer from "inquirer";
4+
import axios from "axios";
5+
import { getProject, getProjects } from "../../../utils/shared.js";
6+
import { readAuthConfig } from "../../../utils/utils.js";
7+
import type { Answers } from "../../app/create.js";
8+
9+
export default class DatabaseMysqlStop extends Command {
10+
static description = "Stop an mysql from a project.";
11+
12+
static examples = ["$ <%= config.bin %> mysql stop"];
13+
14+
public async run(): Promise<void> {
15+
const auth = await readAuthConfig(this);
16+
17+
console.log(chalk.blue.bold("\n Listing all Projects \n"));
18+
19+
const projects = await getProjects(auth, this);
20+
21+
const { project } = await inquirer.prompt<Answers>([
22+
{
23+
choices: projects.map((project) => ({
24+
name: project.name,
25+
value: project,
26+
})),
27+
message: "Select a project to stop the mysql in:",
28+
name: "project",
29+
type: "list",
30+
},
31+
]);
32+
33+
const projectId = project.projectId;
34+
35+
const projectSelected = await getProject(projectId, auth, this);
36+
37+
if (projectSelected.mysql.length === 0) {
38+
this.error(chalk.yellow("No mysql found in this project."));
39+
}
40+
41+
const appAnswers = await inquirer.prompt([
42+
{
43+
// @ts-ignore
44+
choices: projectSelected.mysql.map((app) => ({
45+
name: app.name,
46+
value: app.mysqlId,
47+
})),
48+
message: "Select the mysql to stop:",
49+
name: "selectedApp",
50+
type: "list",
51+
},
52+
]);
53+
54+
const mysqlId = appAnswers.selectedApp;
55+
56+
const confirmAnswers = await inquirer.prompt([
57+
{
58+
default: false,
59+
message: "Are you sure you want to stop this mysql?",
60+
name: "confirmDelete",
61+
type: "confirm",
62+
},
63+
]);
64+
65+
if (!confirmAnswers.confirmDelete) {
66+
this.error(chalk.yellow("mysql stop cancelled."));
67+
}
68+
69+
const response = await axios.post(
70+
`${auth.url}/api/trpc/mysql.stop`,
71+
{
72+
json: {
73+
mysqlId,
74+
},
75+
},
76+
{
77+
headers: {
78+
Authorization: `Bearer ${auth.token}`,
79+
"Content-Type": "application/json",
80+
},
81+
},
82+
);
83+
84+
if (response.status !== 200) {
85+
this.error(chalk.red("Error stopping mysql"));
86+
}
87+
this.log(chalk.green("Mysql stop successful."));
88+
}
89+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { Command } from "@oclif/core";
2+
import chalk from "chalk";
3+
import inquirer from "inquirer";
4+
import axios from "axios";
5+
import { getProject, getProjects } from "../../../utils/shared.js";
6+
import { readAuthConfig } from "../../../utils/utils.js";
7+
import type { Answers } from "../../app/create.js";
8+
9+
export default class DatabasePostgresStop extends Command {
10+
static description = "Stop an postgres from a project.";
11+
12+
static examples = ["$ <%= config.bin %> postgres stop"];
13+
14+
public async run(): Promise<void> {
15+
const auth = await readAuthConfig(this);
16+
17+
console.log(chalk.blue.bold("\n Listing all Projects \n"));
18+
19+
const projects = await getProjects(auth, this);
20+
21+
const { project } = await inquirer.prompt<Answers>([
22+
{
23+
choices: projects.map((project) => ({
24+
name: project.name,
25+
value: project,
26+
})),
27+
message: "Select a project to stop the postgres in:",
28+
name: "project",
29+
type: "list",
30+
},
31+
]);
32+
33+
const projectId = project.projectId;
34+
35+
const projectSelected = await getProject(projectId, auth, this);
36+
37+
if (projectSelected.postgres.length === 0) {
38+
this.error(chalk.yellow("No postgres found in this project."));
39+
}
40+
41+
const appAnswers = await inquirer.prompt([
42+
{
43+
// @ts-ignore
44+
choices: projectSelected.postgres.map((app) => ({
45+
name: app.name,
46+
value: app.postgresId,
47+
})),
48+
message: "Select the postgres to stop:",
49+
name: "selectedApp",
50+
type: "list",
51+
},
52+
]);
53+
54+
const postgresId = appAnswers.selectedApp;
55+
56+
const confirmAnswers = await inquirer.prompt([
57+
{
58+
default: false,
59+
message: "Are you sure you want to stop this postgres?",
60+
name: "confirmDelete",
61+
type: "confirm",
62+
},
63+
]);
64+
65+
if (!confirmAnswers.confirmDelete) {
66+
this.error(chalk.yellow("postgres stop cancelled."));
67+
}
68+
69+
const response = await axios.post(
70+
`${auth.url}/api/trpc/postgres.stop`,
71+
{
72+
json: {
73+
postgresId,
74+
},
75+
},
76+
{
77+
headers: {
78+
Authorization: `Bearer ${auth.token}`,
79+
"Content-Type": "application/json",
80+
},
81+
},
82+
);
83+
84+
if (response.status !== 200) {
85+
this.error(chalk.red("Error stopping postgres"));
86+
}
87+
this.log(chalk.green("Postgres stop successful."));
88+
}
89+
}

0 commit comments

Comments
 (0)