-
Notifications
You must be signed in to change notification settings - Fork 385
/
Copy pathget.ts
59 lines (51 loc) · 1.25 KB
/
get.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
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 = 'get';
export let helpCommand = 'help get';
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();
if (Context === 'all')
{
util.log('\n' + consts.COMANDS_CONTEXT_ERROR + '\n');
rl.prompt();
return;
}
let argvs = util.argsFilter(argv);
if (argvs.length < 2)
{
agent.handle(helpCommand, msg, rl, client);
return;
}
client.request('watchServer', {
comd: commandId,
param: comd,
context: Context
}, function (err: Error, data:{ msg: { [key: string]: any }})
{
if (err) console.log(err);
else util.formatOutput(commandId, data);
rl.prompt();
});
}
}