-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcli.js
108 lines (97 loc) · 3.47 KB
/
cli.js
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// add an empty argument to the front in case the package is compiled to native code
if (process.isPackaged) {
process.argv.unshift('');
}
const program = require('commander');
const path = require('path');
const readline = require('readline');
if (process.argv.includes('--service')) {
global.appRoot = path.resolve(path.dirname(process.execPath));
process.argv = process.argv.filter((arg) => arg !== '--service');
} else {
global.appRoot = path.resolve('.');
}
const { Agent, updateConfigs } = require('./src/service/agent');
const config = require('./src/core/config');
const packageJson = require('./package.json');
const version = `Version: ${packageJson.version}`;
config.version = packageJson.version;
program
.command('config')
.option('-s, --server-url <value>', 'Katalon Analytics URL')
.option('-u, --username <value>', 'Email')
.option('-p, --apikey <value>', 'API key')
.option('-t, --organizationid <value>', 'Organization ID')
.option('-a, --agent-name <value>', 'Agent name')
.option('-c, --config <value>', 'Configuration file path')
.option('-x, --proxy <value>', 'HTTTP/HTTPS Proxy')
.option('--proxy-exclude-list <value>', 'Proxy excluded URLs')
.option('--log-level <value>', 'Log level (ALL < TRACE < DEBUG < INFO < WARN < ERROR < FATAL < MARK < OFF)')
.option('--xvfb-run <value>', 'xvfb-run options')
.option('--x11-display <value>', 'x11 DISPLAY environment variable')
.option('--keep-files', 'Keep test project temporary files')
.option('--no-keep-files', 'Remove test project temporary files (default behavior)')
.action((command) => {
const options = {
serverUrl: command.serverUrl,
email: command.username,
apikey: command.apikey,
organizationId: command.organizationid,
agentName: command.agentName,
configPath: command.config,
proxy: command.proxy,
proxyExcludeList: command.proxyExcludeList,
logLevel: command.logLevel,
xvfbRun: command.xvfbRun,
x11Display: command.x11Display,
keepFiles: command.keepFiles,
};
updateConfigs(options);
});
program
.command('start-agent')
.version(version)
.option('-s, --server-url <value>', 'Katalon Analytics URL')
.option('-u, --username <value>', 'Email')
.option('-p, --apikey <value>', 'API key')
.option('-t, --organizationid <value>', 'Organization ID')
.option('-a, --agent-name <value>', 'Agent name')
.option('-c, --config <value>', 'Configuration file path')
.option('-x, --proxy <value>', 'HTTTP/HTTPS Proxy')
.option('--proxy-exclude-list <value>', 'Proxy excluded URLs')
.option('--ci', 'CI mode')
.action((command) => {
const options = {
serverUrl: command.serverUrl,
email: command.username,
apikey: command.apikey,
organizationId: command.organizationid,
agentName: command.agentName,
configPath: command.config,
proxy: command.proxy,
proxyExcludeList: command.proxyExcludeList,
};
if (process.platform === 'win32') {
readline
.createInterface({
input: process.stdin,
output: process.stdout,
})
.on('SIGINT', () => {
process.emit('SIGINT');
});
}
const agent = new Agent(options);
process.on('SIGINT', () => {
agent.stop();
// graceful shutdown
process.exit();
});
if (command.ci) {
agent.startCI().then(() => process.emit('SIGINT'));
} else {
agent.start();
}
});
program.version(version);
program.parse(process.argv);