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

Class HostnamesListCommand

cli/commands/hostnames/list.js:8–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6const tabler = require('../../tabler.js');
7
8class HostnamesListCommand extends Command {
9
10 constructor() {
11
12 super('hostnames', 'list');
13
14 }
15
16 help() {
17
18 return {
19 description: 'Displays created hostname routes from source custom hostnames to target services you own'
20 };
21
22 }
23
24 run(params, callback) {
25
26 let host = 'api.autocode.com';
27 let port = 443;
28
29 let hostname = (params.flags.h && params.flags.h[0]) || '';
30 let matches = hostname.match(/^(https?:\/\/)?(.*?)(:\d+)?$/);
31 let JSONoutput = params.flags.hasOwnProperty('j') || params.vflags.hasOwnProperty('json');
32
33 if (hostname && matches) {
34 host = matches[2];
35 port = parseInt((matches[3] || '').substr(1) || (hostname.indexOf('https') === 0 ? 443 : 80));
36 }
37
38 let resource = new APIResource(host, port);
39 resource.authorize(config.get('ACCESS_TOKEN'));
40
41 resource.request('v1/hostname_routes').index({}, (err, response) => {
42
43 if (err) {
44 return callback(err);
45 }
46
47 if (JSONoutput) {
48 return callback(null, response.data);
49 }
50
51 let fields = ['Hostname', 'Target', 'Created At'];
52
53 return callback(null, tabler(fields, response.data.map((hostnameRoute) => {
54 return {
55 Hostname: hostnameRoute.formatted_hostname,
56 Target: hostnameRoute.target,
57 'Created At': hostnameRoute.created_at
58 };
59 }), true) + '\n');
60
61 });
62
63 }
64
65}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected