| 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 | } |
| 66 | |