-
Notifications
You must be signed in to change notification settings - Fork 375
/
help.ts
76 lines (65 loc) · 1.49 KB
/
help.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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 = 'help';
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)
{
util.errorHandle(argv, rl);
return;
}
let argvs = util.argsFilter(argv);
if (argvs.length > 2)
{
util.errorHandle(argv, rl);
return;
}
if (comd === 'help')
{
help();
rl.prompt();
return;
}
if (consts.COMANDS_MAP[comd as keyof typeof consts.COMANDS_MAP])
{
let INFOS = <Array<any>>consts.COMANDS_MAP[comd as keyof typeof consts.COMANDS_MAP];
for (let i = 0; i < INFOS.length; i++)
{
util.log(INFOS[i]);
}
rl.prompt();
return;
}
util.errorHandle(argv, rl);
}
}
let help = function ()
{
let HELP_INFO_1 = consts.HELP_INFO_1;
for (let i = 0; i < HELP_INFO_1.length; i++)
{
util.log(HELP_INFO_1[i]);
}
let COMANDS_ALL = consts.COMANDS_ALL;
util.log(cliff.stringifyRows(COMANDS_ALL));
let HELP_INFO_2 = consts.HELP_INFO_2;
for (let i = 0; i < HELP_INFO_2.length; i++)
{
util.log(HELP_INFO_2[i]);
}
}