-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathrestart.ts
47 lines (36 loc) · 1.19 KB
/
restart.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
import Command from '../../base.js';
import { Flags } from '@oclif/core';
import { createDebugLogger } from '../../utils/output.js';
export default class AppRestart extends Command {
static description = 'restart an app';
static flags = {
...Command.flags,
app: Flags.string({
char: 'a',
description: 'app id',
}),
};
static aliases = ['restart'];
async run() {
const { flags } = await this.parse(AppRestart);
const debug = createDebugLogger(flags.debug);
await this.setGotConfig(flags);
const app = flags.app || (await this.promptProject());
try {
await this.got.post(`v1/projects/${app}/actions/restart`);
this.log(`App ${app} restarted.`);
} 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 restart the app. Please try again.`);
}
}
}