MCPcopy Create free account
hub / github.com/acode/cli / LogsCommand

Class LogsCommand

cli/commands/logs.js:17–135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15};
16
17class LogsCommand extends Command {
18
19 constructor() {
20
21 super('logs');
22
23 }
24
25 help() {
26
27 return {
28 description: 'Retrieves logs for a given service',
29 args: ['service'],
30 flags: {
31 t: 'The log type you want to retrieve. Allowed values are "stdout" and "stderr".',
32 l: 'The number of log lines you want to retrieve'
33 },
34 vflags: {
35 type: 'The log type you want to retrieve. Allowed values are "stdout" and "stderr".',
36 lines: 'The number of log lines you want to retrieve'
37 }
38 };
39
40 }
41
42 run(params, callback) {
43
44 let host = 'api.autocode.com';
45 let port = 443;
46
47 let hostname = (params.flags.h && params.flags.h[0]) || '';
48 let matches = hostname.match(/^(https?:\/\/)?(.*?)(:\d+)?$/);
49
50 if (hostname && matches) {
51 host = matches[2];
52 port = parseInt((matches[3] || '').substr(1) || (hostname.indexOf('https') === 0 ? 443 : 80));
53 }
54
55 let logType = (params.flags.t || params.vflags.type || [])[0];
56 let lines = Math.max(parseInt((params.flags.l || params.vflags.lines || [])[0]) || 100, 1);
57
58 let queryParams = {
59 count: lines
60 };
61
62 if (logType) {
63 if (VALID_LOG_TYPES.indexOf(logType) === -1) {
64 return callback(new Error(`Log type must be one of: ${VALID_LOG_TYPES.join(', ')}`));
65 } else {
66 queryParams.log_type = logType;
67 }
68 }
69
70 let serviceFilter = params.args[0];
71 if (!serviceFilter) {
72 return callback(new Error('Please enter a service to check logs for in the format: username.service[@environment].*'));
73 }
74

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected