From 5ba74af7b3d698d439cb0ccf590cbb83c3abf0ef Mon Sep 17 00:00:00 2001 From: Austin Godber Date: Sat, 19 Aug 2017 14:27:30 -0700 Subject: [PATCH] fix: retabbing to four spaces --- index.js | 100 ++++++++++++++++++++--------------------- lib/draw.js | 22 ++++----- lib/request.js | 22 ++++----- lib/teraslice.js | 52 ++++++++++----------- spec/teraslice-spec.js | 44 +++++++++--------- 5 files changed, 120 insertions(+), 120 deletions(-) diff --git a/index.js b/index.js index 8e035c3..1ddcffe 100755 --- a/index.js +++ b/index.js @@ -8,52 +8,52 @@ const request = require('request-promise'); const draw = require('./lib/draw'); const argv = require('yargs') - .usage(`Usage: $0 [options] [host]`) - .example(`$0 -p 45678 10.0.0.12`) - .options({ - 'p': { - alias: `port`, - nargs: 1, - number: true, - describe: `Port of Teraslice master node`, - default: 5678, - }, - 't': { - alias: `timeout`, - nargs: 1, - number: true, - describe: `Time between refresh (seconds)`, - default: 2, - }, - }) - .help('h') - .alias('h', `help`) - .argv; + .usage(`Usage: $0 [options] [host]`) + .example(`$0 -p 45678 10.0.0.12`) + .options({ + 'p': { + alias: `port`, + nargs: 1, + number: true, + describe: `Port of Teraslice master node`, + default: 5678, + }, + 't': { + alias: `timeout`, + nargs: 1, + number: true, + describe: `Time between refresh (seconds)`, + default: 2, + }, + }) + .help('h') + .alias('h', `help`) + .argv; -let ts = new Teraslice(argv._[0], argv.p); // host, port -let requestInterval = argv.t * 1000; // convert seconds to ms +let ts = new Teraslice(argv._[0], argv.p); // host, port +let requestInterval = argv.t * 1000; // convert seconds to ms const sections = ['Nodes', 'Workers', 'Slicers', 'Jobs', 'Execution Contexts']; setInterval(function() { - Promise.map(sections, function(section) { - // request info from all API endpoints - return request({ - uri: ts.api[section].url, - resolveWithFullResponse: true, // we want the full response, not just body - simple: false, // promise not rejected in case of 404, handle 404s manually + Promise.map(sections, function(section) { + // request info from all API endpoints + return request({ + uri: ts.api[section].url, + resolveWithFullResponse: true, // we want the full response, not just body + simple: false, // promise not rejected in case of 404, handle 404s manually + }); + }).then(function(responses) { + // populate the ts.api[section].value fields + for (let i = 0; i < responses.length; i++) { + handleResponse(sections[i], responses[i]); + } + return; + }).then(function() { + draw(ts); + }).catch(function(e) { + console.error(`Error: ${e}`); }); - }).then(function(responses) { - // populate the ts.api[section].value fields - for (let i = 0; i < responses.length; i++) { - handleResponse(sections[i], responses[i]); - } - return; - }).then(function() { - draw(ts); - }).catch(function(e) { - console.error(`Error: ${e}`); - }); }, requestInterval); // draw screen at interval /** @@ -62,15 +62,15 @@ setInterval(function() { * @param {object} response Response object from the request-promise library */ function handleResponse(section, response) { - if (response.statusCode == 200) { - if (!response.body) { - ts.api[section].value = ''; + if (response.statusCode == 200) { + if (!response.body) { + ts.api[section].value = ''; + } else { + ts.api[section].value = response.body; + } + } else if (response.statusCode == 404) { + ts.api[section].value = 'Section unavailable'; } else { - ts.api[section].value = response.body; - } - } else if (response.statusCode == 404) { - ts.api[section].value = 'Section unavailable'; - } else { - ts.api[section].value = 'Unexpected Response'; - }; + ts.api[section].value = 'Unexpected Response'; + }; } diff --git a/lib/draw.js b/lib/draw.js index 2df76ee..14cd1a9 100644 --- a/lib/draw.js +++ b/lib/draw.js @@ -10,18 +10,18 @@ const jetty = new Jetty(process.stdout); * @param {string} url complete URL to the API endpoint */ module.exports = function(ts) { - jetty - .clear() - .moveTo([0, 0]); + jetty + .clear() + .moveTo([0, 0]); - let date = new Date(); - for (let section in ts.api) { - if (ts.api.hasOwnProperty(section)) { - process.stdout.write(makeHeader(section)); - process.stdout.write(ts.api[section].value); + let date = new Date(); + for (let section in ts.api) { + if (ts.api.hasOwnProperty(section)) { + process.stdout.write(makeHeader(section)); + process.stdout.write(ts.api[section].value); + } } - } - process.stdout.write(`\nUpdated at: ${date}\n`); + process.stdout.write(`\nUpdated at: ${date}\n`); }; /** @@ -30,7 +30,7 @@ module.exports = function(ts) { * @return {string} s The formatted string to be printed to title. */ function makeHeader(title) { - return ` + return ` ###### ${title} ###### `; diff --git a/lib/request.js b/lib/request.js index 0261635..31d9024 100644 --- a/lib/request.js +++ b/lib/request.js @@ -9,15 +9,15 @@ const request = require('request'); * @param {getEndpointCallback} callback */ module.exports = function(section, url, callback) { - request(url, function(error, response, body) { - if (error) { - callback(error, section); - } else if (response.statusCode == 200) { - callback(null, section, body); - } else if (response.statusCode == 404) { - callback(null, section, 'Section unavailable.'); - } else { - callback(null, section, 'Unexpected Response'); - } - }); + request(url, function(error, response, body) { + if (error) { + callback(error, section); + } else if (response.statusCode == 200) { + callback(null, section, body); + } else if (response.statusCode == 404) { + callback(null, section, 'Section unavailable.'); + } else { + callback(null, section, 'Unexpected Response'); + } + }); }; diff --git a/lib/teraslice.js b/lib/teraslice.js index 6bc47d4..42ceb29 100644 --- a/lib/teraslice.js +++ b/lib/teraslice.js @@ -1,31 +1,31 @@ 'use strict'; module.exports = function(host, port) { - this.host = host || `localhost`; - this.port = port || 5678; - this.baseUrl = `http://${this.host}:${this.port}`; - this.param = '?size=8'; + this.host = host || `localhost`; + this.port = port || 5678; + this.baseUrl = `http://${this.host}:${this.port}`; + this.param = '?size=8'; - this.api = { - 'Nodes': { - 'url': `${this.baseUrl}/txt/nodes${this.param}`, - 'value': '', - }, - 'Workers': { - 'url': `${this.baseUrl}/txt/workers${this.param}`, - 'value': '', - }, - 'Slicers': { - 'url': `${this.baseUrl}/txt/slicers${this.param}`, - 'value': '', - }, - 'Jobs': { - 'url': `${this.baseUrl}/txt/jobs${this.param}`, - 'value': '', - }, - 'Execution Contexts': { - 'url': `${this.baseUrl}/txt/ex${this.param}`, - 'value': '', - }, - }; + this.api = { + 'Nodes': { + 'url': `${this.baseUrl}/txt/nodes${this.param}`, + 'value': '', + }, + 'Workers': { + 'url': `${this.baseUrl}/txt/workers${this.param}`, + 'value': '', + }, + 'Slicers': { + 'url': `${this.baseUrl}/txt/slicers${this.param}`, + 'value': '', + }, + 'Jobs': { + 'url': `${this.baseUrl}/txt/jobs${this.param}`, + 'value': '', + }, + 'Execution Contexts': { + 'url': `${this.baseUrl}/txt/ex${this.param}`, + 'value': '', + }, + }; }; diff --git a/spec/teraslice-spec.js b/spec/teraslice-spec.js index 9bc042e..3eb39dd 100644 --- a/spec/teraslice-spec.js +++ b/spec/teraslice-spec.js @@ -3,33 +3,33 @@ const Teraslice = require('../lib/teraslice'); describe('Default Teraslice', function() { - let ts = new Teraslice(); + let ts = new Teraslice(); - it('has a list of api endpoints accessible at .api', function() { - expect(typeof ts.api).toBe('object'); - expect(ts.api['Nodes'].url).toBe('http://localhost:5678/txt/nodes?size=8'); - expect(ts.api.Nodes.value).toBe(''); - }); + it('has a list of api endpoints accessible at .api', function() { + expect(typeof ts.api).toBe('object'); + expect(ts.api['Nodes'].url).toBe('http://localhost:5678/txt/nodes?size=8'); + expect(ts.api.Nodes.value).toBe(''); + }); - it('uses localhost as the default host', function() { - expect(ts.host).toBe('localhost'); - expect(ts.baseUrl).toBe('http://localhost:5678'); - }); + it('uses localhost as the default host', function() { + expect(ts.host).toBe('localhost'); + expect(ts.baseUrl).toBe('http://localhost:5678'); + }); - it('can be moified to store the results from the API', function() { - expect(ts.api.Nodes.value).toBe(''); - ts.api.Nodes.value = 'test'; - expect(ts.api.Nodes.value).toBe('test'); - expect(ts.api['Nodes'].value).toBe('test'); - }); + it('can be moified to store the results from the API', function() { + expect(ts.api.Nodes.value).toBe(''); + ts.api.Nodes.value = 'test'; + expect(ts.api.Nodes.value).toBe('test'); + expect(ts.api['Nodes'].value).toBe('test'); + }); }); describe('Custom Teraslice', function() { - let ts = new Teraslice('10.0.0.0', 1234); + let ts = new Teraslice('10.0.0.0', 1234); - it('uses localhost as the default host', function() { - expect(ts.host).toBe('10.0.0.0'); - expect(ts.baseUrl).toBe('http://10.0.0.0:1234'); - expect(ts.api['Execution Contexts'].url).toBe('http://10.0.0.0:1234/txt/ex?size=8'); - }); + it('uses localhost as the default host', function() { + expect(ts.host).toBe('10.0.0.0'); + expect(ts.baseUrl).toBe('http://10.0.0.0:1234'); + expect(ts.api['Execution Contexts'].url).toBe('http://10.0.0.0:1234/txt/ex?size=8'); + }); });