/
stop.ts
54 lines (44 loc) · 1.29 KB
/
stop.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import axios from "axios";
import Command from "../../base";
import { flags } from "@oclif/command";
import { createDebugLogger } from "../../utils/output";
export default class AppStop extends Command {
static description = "stop an app";
static flags = {
...Command.flags,
app: flags.string({
char: "a",
description: "app id",
}),
};
static aliases = ["stop"];
async run() {
const { flags } = this.parse(AppStop);
const debug = createDebugLogger(flags.debug);
this.setAxiosConfig({
...this.readGlobalConfig(),
...flags,
});
const app = flags.app || (await this.promptProject());
try {
await axios.post(
`/v1/projects/${app}/actions/scale`,
{ scale: 0 },
this.axiosConfig
);
this.log(`App ${app} stopped.`);
} catch (error) {
debug(error.message);
if (error.response && error.response.data) {
debug(JSON.stringify(error.response.data));
}
if (error.response && error.response.status === 404) {
this.error(`Could not find the app.`);
}
if (error.response && error.response.status === 409) {
this.error(`Another operation is already running. Please wait.`);
}
this.error(`Could not stop the app. Please try again.`);
}
}
}