MCPcopy
hub / github.com/acode/cli / run

Method run

cli/commands/logs.js:42–133  ·  view source on GitHub ↗
(params, callback)

Source from the content-addressed store, hash-verified

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
75 let wildcard = serviceFilter && serviceFilter[serviceFilter.length - 1] === '*';
76 if (wildcard) {
77 serviceFilter = serviceFilter.substr(0, serviceFilter.length -1);
78 if (['.', ']'].indexOf(serviceFilter[serviceFilter.length - 1]) === -1) {
79 return callback(new Error('Sorry, can not wildcard incomplete service or function names'));
80 }
81 }
82
83 let serviceParts = (serviceFilter || '').split('.');
84 let username = serviceParts[0];
85 let service = serviceParts[1];
86 let pathname = serviceParts.slice(1).join('.');
87 if (pathname) {
88 let env = /^(.+?)\[@(.+?)\](?:\.(.*?))?$/.exec(pathname);
89 if (env) {
90 service = env[1];
91 let environment = env[2];
92 let functionName = env[3] || '';
93 if (/^\d+/.exec(environment)) {
94 queryParams.version = environment;
95 } else {
96 queryParams.environment = environment;
97 }
98 if (!wildcard || functionName) {
99 queryParams.function_name = functionName.split('.').join('/');

Callers

nothing calls this directly

Calls 2

getMethod · 0.80
requestMethod · 0.80

Tested by

no test coverage detected