mirror of
https://github.com/Dokploy/cli.git
synced 2026-06-27 01:55:23 +02:00
feat: add stop command
This commit is contained in:
89
src/commands/database/mariadb/stop.ts
Normal file
89
src/commands/database/mariadb/stop.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import { Command } from "@oclif/core";
|
||||
import chalk from "chalk";
|
||||
import inquirer from "inquirer";
|
||||
import axios from "axios";
|
||||
import { getProject, getProjects } from "../../../utils/shared.js";
|
||||
import { readAuthConfig } from "../../../utils/utils.js";
|
||||
import type { Answers } from "../../app/create.js";
|
||||
|
||||
export default class DatabaseMariadbStop extends Command {
|
||||
static description = "Stop an mariadb from a project.";
|
||||
|
||||
static examples = ["$ <%= config.bin %> mariadb stop"];
|
||||
|
||||
public async run(): Promise<void> {
|
||||
const auth = await readAuthConfig(this);
|
||||
|
||||
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
||||
|
||||
const projects = await getProjects(auth, this);
|
||||
|
||||
const { project } = await inquirer.prompt<Answers>([
|
||||
{
|
||||
choices: projects.map((project) => ({
|
||||
name: project.name,
|
||||
value: project,
|
||||
})),
|
||||
message: "Select a project to stop the mariadb in:",
|
||||
name: "project",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
|
||||
const projectId = project.projectId;
|
||||
|
||||
const projectSelected = await getProject(projectId, auth, this);
|
||||
|
||||
if (projectSelected.mariadb.length === 0) {
|
||||
this.error(chalk.yellow("No mariadb found in this project."));
|
||||
}
|
||||
|
||||
const appAnswers = await inquirer.prompt([
|
||||
{
|
||||
// @ts-ignore
|
||||
choices: projectSelected.mariadb.map((app) => ({
|
||||
name: app.name,
|
||||
value: app.mariadbId,
|
||||
})),
|
||||
message: "Select the mariadb to stop:",
|
||||
name: "selectedApp",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
|
||||
const mariadbId = appAnswers.selectedApp;
|
||||
|
||||
const confirmAnswers = await inquirer.prompt([
|
||||
{
|
||||
default: false,
|
||||
message: "Are you sure you want to stop this mariadb?",
|
||||
name: "confirmDelete",
|
||||
type: "confirm",
|
||||
},
|
||||
]);
|
||||
|
||||
if (!confirmAnswers.confirmDelete) {
|
||||
this.error(chalk.yellow("Mariadb stop cancelled."));
|
||||
}
|
||||
|
||||
const response = await axios.post(
|
||||
`${auth.url}/api/trpc/mariadb.stop`,
|
||||
{
|
||||
json: {
|
||||
mariadbId,
|
||||
},
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${auth.token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
if (response.status !== 200) {
|
||||
this.error(chalk.red("Error stopping mariadb"));
|
||||
}
|
||||
this.log(chalk.green("Mariadb stop successful."));
|
||||
}
|
||||
}
|
||||
89
src/commands/database/mongo/stop.ts
Normal file
89
src/commands/database/mongo/stop.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import { Command } from "@oclif/core";
|
||||
import chalk from "chalk";
|
||||
import inquirer from "inquirer";
|
||||
import axios from "axios";
|
||||
import { getProject, getProjects } from "../../../utils/shared.js";
|
||||
import { readAuthConfig } from "../../../utils/utils.js";
|
||||
import type { Answers } from "../../app/create.js";
|
||||
|
||||
export default class DatabaseMongoStop extends Command {
|
||||
static description = "Stop an mongo from a project.";
|
||||
|
||||
static examples = ["$ <%= config.bin %> mongo stop"];
|
||||
|
||||
public async run(): Promise<void> {
|
||||
const auth = await readAuthConfig(this);
|
||||
|
||||
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
||||
|
||||
const projects = await getProjects(auth, this);
|
||||
|
||||
const { project } = await inquirer.prompt<Answers>([
|
||||
{
|
||||
choices: projects.map((project) => ({
|
||||
name: project.name,
|
||||
value: project,
|
||||
})),
|
||||
message: "Select a project to stop the mongo in:",
|
||||
name: "project",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
|
||||
const projectId = project.projectId;
|
||||
|
||||
const projectSelected = await getProject(projectId, auth, this);
|
||||
|
||||
if (projectSelected.mongo.length === 0) {
|
||||
this.error(chalk.yellow("No mongo found in this project."));
|
||||
}
|
||||
|
||||
const appAnswers = await inquirer.prompt([
|
||||
{
|
||||
// @ts-ignore
|
||||
choices: projectSelected.mongo.map((app) => ({
|
||||
name: app.name,
|
||||
value: app.mongoId,
|
||||
})),
|
||||
message: "Select the mongo to stop:",
|
||||
name: "selectedApp",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
|
||||
const mongoId = appAnswers.selectedApp;
|
||||
|
||||
const confirmAnswers = await inquirer.prompt([
|
||||
{
|
||||
default: false,
|
||||
message: "Are you sure you want to stop this mongo?",
|
||||
name: "confirmDelete",
|
||||
type: "confirm",
|
||||
},
|
||||
]);
|
||||
|
||||
if (!confirmAnswers.confirmDelete) {
|
||||
this.error(chalk.yellow("mongo stop cancelled."));
|
||||
}
|
||||
|
||||
const response = await axios.post(
|
||||
`${auth.url}/api/trpc/mongo.stop`,
|
||||
{
|
||||
json: {
|
||||
mongoId,
|
||||
},
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${auth.token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
if (response.status !== 200) {
|
||||
this.error(chalk.red("Error stopping mongo"));
|
||||
}
|
||||
this.log(chalk.green("Mongo stop successful."));
|
||||
}
|
||||
}
|
||||
89
src/commands/database/mysql/stop.ts
Normal file
89
src/commands/database/mysql/stop.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import { Command } from "@oclif/core";
|
||||
import chalk from "chalk";
|
||||
import inquirer from "inquirer";
|
||||
import axios from "axios";
|
||||
import { getProject, getProjects } from "../../../utils/shared.js";
|
||||
import { readAuthConfig } from "../../../utils/utils.js";
|
||||
import type { Answers } from "../../app/create.js";
|
||||
|
||||
export default class DatabaseMysqlStop extends Command {
|
||||
static description = "Stop an mysql from a project.";
|
||||
|
||||
static examples = ["$ <%= config.bin %> mysql stop"];
|
||||
|
||||
public async run(): Promise<void> {
|
||||
const auth = await readAuthConfig(this);
|
||||
|
||||
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
||||
|
||||
const projects = await getProjects(auth, this);
|
||||
|
||||
const { project } = await inquirer.prompt<Answers>([
|
||||
{
|
||||
choices: projects.map((project) => ({
|
||||
name: project.name,
|
||||
value: project,
|
||||
})),
|
||||
message: "Select a project to stop the mysql in:",
|
||||
name: "project",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
|
||||
const projectId = project.projectId;
|
||||
|
||||
const projectSelected = await getProject(projectId, auth, this);
|
||||
|
||||
if (projectSelected.mysql.length === 0) {
|
||||
this.error(chalk.yellow("No mysql found in this project."));
|
||||
}
|
||||
|
||||
const appAnswers = await inquirer.prompt([
|
||||
{
|
||||
// @ts-ignore
|
||||
choices: projectSelected.mysql.map((app) => ({
|
||||
name: app.name,
|
||||
value: app.mysqlId,
|
||||
})),
|
||||
message: "Select the mysql to stop:",
|
||||
name: "selectedApp",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
|
||||
const mysqlId = appAnswers.selectedApp;
|
||||
|
||||
const confirmAnswers = await inquirer.prompt([
|
||||
{
|
||||
default: false,
|
||||
message: "Are you sure you want to stop this mysql?",
|
||||
name: "confirmDelete",
|
||||
type: "confirm",
|
||||
},
|
||||
]);
|
||||
|
||||
if (!confirmAnswers.confirmDelete) {
|
||||
this.error(chalk.yellow("mysql stop cancelled."));
|
||||
}
|
||||
|
||||
const response = await axios.post(
|
||||
`${auth.url}/api/trpc/mysql.stop`,
|
||||
{
|
||||
json: {
|
||||
mysqlId,
|
||||
},
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${auth.token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
if (response.status !== 200) {
|
||||
this.error(chalk.red("Error stopping mysql"));
|
||||
}
|
||||
this.log(chalk.green("Mysql stop successful."));
|
||||
}
|
||||
}
|
||||
89
src/commands/database/postgres/stop.ts
Normal file
89
src/commands/database/postgres/stop.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import { Command } from "@oclif/core";
|
||||
import chalk from "chalk";
|
||||
import inquirer from "inquirer";
|
||||
import axios from "axios";
|
||||
import { getProject, getProjects } from "../../../utils/shared.js";
|
||||
import { readAuthConfig } from "../../../utils/utils.js";
|
||||
import type { Answers } from "../../app/create.js";
|
||||
|
||||
export default class DatabasePostgresStop extends Command {
|
||||
static description = "Stop an postgres from a project.";
|
||||
|
||||
static examples = ["$ <%= config.bin %> postgres stop"];
|
||||
|
||||
public async run(): Promise<void> {
|
||||
const auth = await readAuthConfig(this);
|
||||
|
||||
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
||||
|
||||
const projects = await getProjects(auth, this);
|
||||
|
||||
const { project } = await inquirer.prompt<Answers>([
|
||||
{
|
||||
choices: projects.map((project) => ({
|
||||
name: project.name,
|
||||
value: project,
|
||||
})),
|
||||
message: "Select a project to stop the postgres in:",
|
||||
name: "project",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
|
||||
const projectId = project.projectId;
|
||||
|
||||
const projectSelected = await getProject(projectId, auth, this);
|
||||
|
||||
if (projectSelected.postgres.length === 0) {
|
||||
this.error(chalk.yellow("No postgres found in this project."));
|
||||
}
|
||||
|
||||
const appAnswers = await inquirer.prompt([
|
||||
{
|
||||
// @ts-ignore
|
||||
choices: projectSelected.postgres.map((app) => ({
|
||||
name: app.name,
|
||||
value: app.postgresId,
|
||||
})),
|
||||
message: "Select the postgres to stop:",
|
||||
name: "selectedApp",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
|
||||
const postgresId = appAnswers.selectedApp;
|
||||
|
||||
const confirmAnswers = await inquirer.prompt([
|
||||
{
|
||||
default: false,
|
||||
message: "Are you sure you want to stop this postgres?",
|
||||
name: "confirmDelete",
|
||||
type: "confirm",
|
||||
},
|
||||
]);
|
||||
|
||||
if (!confirmAnswers.confirmDelete) {
|
||||
this.error(chalk.yellow("postgres stop cancelled."));
|
||||
}
|
||||
|
||||
const response = await axios.post(
|
||||
`${auth.url}/api/trpc/postgres.stop`,
|
||||
{
|
||||
json: {
|
||||
postgresId,
|
||||
},
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${auth.token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
if (response.status !== 200) {
|
||||
this.error(chalk.red("Error stopping postgres"));
|
||||
}
|
||||
this.log(chalk.green("Postgres stop successful."));
|
||||
}
|
||||
}
|
||||
89
src/commands/database/redis/stop.ts
Normal file
89
src/commands/database/redis/stop.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import { Command } from "@oclif/core";
|
||||
import chalk from "chalk";
|
||||
import inquirer from "inquirer";
|
||||
import axios from "axios";
|
||||
import { getProject, getProjects } from "../../../utils/shared.js";
|
||||
import { readAuthConfig } from "../../../utils/utils.js";
|
||||
import type { Answers } from "../../app/create.js";
|
||||
|
||||
export default class DatabaseRedisStop extends Command {
|
||||
static description = "Stop an redis from a project.";
|
||||
|
||||
static examples = ["$ <%= config.bin %> redis stop"];
|
||||
|
||||
public async run(): Promise<void> {
|
||||
const auth = await readAuthConfig(this);
|
||||
|
||||
console.log(chalk.blue.bold("\n Listing all Projects \n"));
|
||||
|
||||
const projects = await getProjects(auth, this);
|
||||
|
||||
const { project } = await inquirer.prompt<Answers>([
|
||||
{
|
||||
choices: projects.map((project) => ({
|
||||
name: project.name,
|
||||
value: project,
|
||||
})),
|
||||
message: "Select a project to stop the redis in:",
|
||||
name: "project",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
|
||||
const projectId = project.projectId;
|
||||
|
||||
const projectSelected = await getProject(projectId, auth, this);
|
||||
|
||||
if (projectSelected.redis.length === 0) {
|
||||
this.error(chalk.yellow("No redis found in this project."));
|
||||
}
|
||||
|
||||
const appAnswers = await inquirer.prompt([
|
||||
{
|
||||
// @ts-ignore
|
||||
choices: projectSelected.redis.map((app) => ({
|
||||
name: app.name,
|
||||
value: app.redisId,
|
||||
})),
|
||||
message: "Select the redis to stop:",
|
||||
name: "selectedApp",
|
||||
type: "list",
|
||||
},
|
||||
]);
|
||||
|
||||
const redisId = appAnswers.selectedApp;
|
||||
|
||||
const confirmAnswers = await inquirer.prompt([
|
||||
{
|
||||
default: false,
|
||||
message: "Are you sure you want to stop this redis?",
|
||||
name: "confirmDelete",
|
||||
type: "confirm",
|
||||
},
|
||||
]);
|
||||
|
||||
if (!confirmAnswers.confirmDelete) {
|
||||
this.error(chalk.yellow("redis stop cancelled."));
|
||||
}
|
||||
|
||||
const response = await axios.post(
|
||||
`${auth.url}/api/trpc/redis.stop`,
|
||||
{
|
||||
json: {
|
||||
redisId,
|
||||
},
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${auth.token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
if (response.status !== 200) {
|
||||
this.error(chalk.red("Error stopping redis"));
|
||||
}
|
||||
this.log(chalk.green("Redis stop successful."));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user