-
Notifications
You must be signed in to change notification settings - Fork 374
/
stop.ts
60 lines (53 loc) · 1.26 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
55
56
57
58
59
60
import { getLogger } from 'pinus-logger';
let logger = getLogger(__filename);
import * as util from '../util';
import { consts } from '../consts';
import * as cliff from 'cliff';
import { ICommand, AgentCommand } from '../command';
import { ReadLine } from 'readline';
import { AdminClient } from 'pinus-admin';
export default function (opts:object)
{
return new Command(opts);
};
export let commandId = 'stop';
export let helpCommand = 'help stop';
export class Command implements ICommand
{
constructor(opts:object)
{
}
handle(agent: AgentCommand, comd: string, argv: string, msg: {[key:string]: string}, rl: ReadLine, client: AdminClient): void
{
if (!comd)
{
agent.handle(helpCommand, msg, rl, client);
return;
}
let Context = agent.getContext();
let argvs = util.argsFilter(argv);
let ids: Array<any> = [];
if (comd !== 'all')
{
ids = argvs.slice(1);
}
rl.question(consts.STOP_QUESTION_INFO, function (answer)
{
if (answer === 'yes')
{
client.request(consts.CONSOLE_MODULE, {
signal: "stop",
ids: ids
}, function (err:Error, data:{ msg: { [key: string]: any }})
{
if (err) console.log(err);
else util.formatOutput(comd, data);
rl.prompt();
});
} else
{
rl.prompt();
}
});
}
}