Skip to content

Commit

Permalink
Remove colors from output
Browse files Browse the repository at this point in the history
  • Loading branch information
knolleary committed Jun 3, 2020
1 parent 942b2a2 commit 43adba9
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 34 deletions.
6 changes: 3 additions & 3 deletions lib/commands/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ function command(argv,result) {
return request.request('/auth/login',{}).then(function(resp) {
if (resp.type) {
if (resp.type == "credentials") {
prompt.read({prompt:"Username:".bold},function(err, username) {
prompt.read({prompt:"Password:".bold,silent: true},function(err, password) {
prompt.read({prompt:"Username:"},function(err, username) {
prompt.read({prompt:"Password:",silent: true},function(err, password) {
request.request('/auth/token', {
method: "POST",
data: {
Expand All @@ -36,7 +36,7 @@ function command(argv,result) {
}
}).then(function(resp) {
config.tokens(resp);
result.log("Logged in".green);
result.log("Logged in");
}).catch(function(resp) {
result.warn("Login failed");
});
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function command(argv,result) {
if (info.data && info.data.length > 0) {
for (var i = 0; i < info.data.length; i++) {
var n = info.data[i];
var label = info.data[i].name.cyan.bold + (" - " + info.data[i].description).grey;
var label = info.data[i].name + " - " + info.data[i].description;
var index = label.indexOf(module);
matches.push({
label: label,
Expand Down
4 changes: 2 additions & 2 deletions lib/commands/target.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ function command(argv,result) {
target = target.slice(0, target.length - 1);
}
config.target(target);

}
result.log("Target: " + config.target().cyan.bold);
result.log("Target: " + config.target());
}

command.alias = "target";
Expand Down
7 changes: 3 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
**/

var config = require("./config");
var colors = require("colors/safe");

var commands = {
"target": require("./commands/target"),
Expand All @@ -33,11 +32,11 @@ var commands = {
};

function help() {
var helpText = colors.bold("Usage:") + "\n" +
var helpText = "Usage:" + "\n" +
" node-red-admin <command> [args] [--help] [--userDir DIR] [--json]\n\n" +
colors.bold("Description:") + "\n" +
"Description:" + "\n" +
" Node-RED command-line client\n\n" +
colors.bold("Commands:\n") +
"Commands:\n" +
" target - Set or view the target URL and port like http:https://localhost:1880\n" +
" login - Log user in to the target of the Node-RED admin API\n" +
" list - List all of the installed nodes\n" +
Expand Down
41 changes: 20 additions & 21 deletions lib/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

var Table = require('cli-table');
var util = require("util");
var colors = require("colors/safe");

var outputFormat = "text";

Expand All @@ -34,8 +33,8 @@ function logModule(result) {
return;
}
var table = plainTable({plain:true});
table.push([colors.bold("Module:"),result.name]);
table.push([colors.bold("Version:"),result.version]);
table.push(["Module:",result.name]);
table.push(["Version:",result.version]);
console.log(table.toString());
console.log();
logNodeList(result.nodes);
Expand Down Expand Up @@ -64,12 +63,12 @@ function logNodeSet(node) {
}
}
var table = plainTable({plain:true});
table.push([colors.bold("Name:"), colors.cyan(colors.bold(node.id))]);
table.push([colors.bold("Module:"),node.module]);
table.push([colors.bold("Version:"),node.version]);
table.push(["Name:", node.id]);
table.push(["Module:",node.module]);
table.push(["Version:",node.version]);

table.push([colors.bold("Types:"), node.types.join(", ")]);
table.push([colors.bold("State:"), (node.err?colors.red(node.err):(node.enabled?"enabled":"disabled"))]);
table.push(["Types:", node.types.join(", ")]);
table.push(["State:", (node.err?node.err:(node.enabled?"enabled":"disabled"))]);

console.log(table.toString());
}
Expand All @@ -94,23 +93,23 @@ function logNodeList(nodes) {
return 0;
});
var nodeTable = plainTable();
nodeTable.push([colors.bold("Nodes"),colors.bold("Types"),colors.bold("State")]);
nodeTable.push(["Nodes","Types","State"]);

for(var i=0;i<nodes.length;i++) {
var node = nodes[i];
var state = node.enabled?(node.err?colors.red("error"):"enabled"):colors.grey("disabled");
var state = node.enabled?(node.err?"error":"enabled"):"disabled";
var enabled = node.enabled&&!node.err;

var types = "";
for (var j=0;j<node.types.length;j++) {
types += (j>0?"\n":"")+(enabled?node.types[j]:colors.grey(node.types[j]));
types += (j>0?"\n":"")+(enabled?node.types[j]:node.types[j]);
}
if (types.length === 0) {
types = colors.grey("none");
types = "none";
}

nodeTable.push([enabled?colors.cyan(colors.bold(node.id)):colors.grey(node.id),
enabled?types:colors.grey(types),
nodeTable.push([enabled?node.id:node.id,
enabled?types:types,
state]);
}
console.log(nodeTable.toString());
Expand Down Expand Up @@ -150,22 +149,22 @@ module.exports = {
warn:function(msg) {
if (msg.response) {
if (msg.response.status === 401) {
console.warn("Not logged in. Use '"+colors.yellow(colors.bold("node-red-admin login"))+"' to log in.");
console.warn("Not logged in. Use 'node-red-admin login' to log in.");
} else if (msg.response.data) {
console.warn(colors.magenta(msg.response.status+": "+msg.response.data.message));
console.warn(msg.response.status+": "+msg.response.data.message);
} else {
console.warn(colors.magenta(msg.response.status+": "+msg.toString()));
console.warn(msg.response.status+": "+msg.toString());
}
} else {
console.warn(colors.magenta(msg.toString()));
console.warn(msg.toString());
}
},
help:function(command) {
var helpText = colors.bold("Usage:") + "\n" +
var helpText = "Usage:" + "\n" +
" node-red-admin " + command.usage + "\n\n" +
colors.bold("Description:") + "\n" +
"Description:" + "\n" +
" " + command.description + "\n\n" +
colors.bold("Options:") + "\n" +
"Options:" + "\n" +
(command.options ? " " + command.options + "\n" : "") +
" -h|? --help display this help text and exit";
console.log(helpText);
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-admin",
"version": "0.2.2",
"version": "0.2.3",
"description": "The Node-RED admin command line interface",
"homepage": "http:https://nodered.org",
"bugs": {
Expand Down Expand Up @@ -31,7 +31,6 @@
"axios": "0.19.2",
"bcryptjs": "^2.4.3",
"cli-table": "^0.3.1",
"colors": "^1.4.0",
"minimist": "^1.2.5",
"read": "^1.0.7"
},
Expand Down
1 change: 0 additions & 1 deletion test/lib/commands/result_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
var colors = require("colors");
var sinon = require("sinon");
var result = require("../../../lib/result");

Expand Down

0 comments on commit 43adba9

Please sign in to comment.