node-red-admin
Advanced tools
Comparing version 0.2.2 to 0.2.3
@@ -21,17 +21,28 @@ /** | ||
var module = argv._[1]; | ||
var url = argv._[2]; | ||
if (!module) { | ||
return result.help(command); | ||
} | ||
var data = {} | ||
var m = /^(.+)@(.+)$/.exec(module); | ||
if (m) { | ||
data.module = m[1]; | ||
data.version = m[2] | ||
} else { | ||
data.module = module; | ||
} | ||
if (url) { | ||
data.url = url; | ||
} | ||
return request.request('/nodes', { | ||
method: "POST", | ||
data: { | ||
module: module | ||
} | ||
data: data | ||
}).then(result.logDetails).catch(result.warn); | ||
} | ||
command.alias = "install"; | ||
command.usage = command.alias+" <module>"; | ||
command.description = "Install the module from NPM"; | ||
command.usage = command.alias+" <module> [<url>]"; | ||
command.description = "Install a module."; | ||
module.exports = command; |
@@ -26,4 +26,4 @@ /** | ||
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', { | ||
@@ -40,3 +40,3 @@ method: "POST", | ||
config.tokens(resp); | ||
result.log("Logged in".green); | ||
result.log("Logged in"); | ||
}).catch(function(resp) { | ||
@@ -43,0 +43,0 @@ result.warn("Login failed"); |
@@ -38,3 +38,3 @@ /** | ||
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); | ||
@@ -41,0 +41,0 @@ matches.push({ |
@@ -30,5 +30,5 @@ /** | ||
config.target(target); | ||
} | ||
result.log("Target: " + config.target().cyan.bold); | ||
result.log("Target: " + config.target()); | ||
} | ||
@@ -35,0 +35,0 @@ |
@@ -18,3 +18,2 @@ /** | ||
var config = require("./config"); | ||
var colors = require("colors/safe"); | ||
@@ -37,7 +36,7 @@ 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://localhost:1880\n" + | ||
@@ -44,0 +43,0 @@ " login - Log user in to the target of the Node-RED admin API\n" + |
@@ -19,3 +19,2 @@ /** | ||
var util = require("util"); | ||
var colors = require("colors/safe"); | ||
@@ -38,4 +37,4 @@ var outputFormat = "text"; | ||
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()); | ||
@@ -69,8 +68,8 @@ console.log(); | ||
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"))]); | ||
@@ -100,19 +99,21 @@ console.log(table.toString()); | ||
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])); | ||
if (node.types) { | ||
for (var j=0;j<node.types.length;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]); | ||
@@ -155,20 +156,27 @@ } | ||
warn:function(msg) { | ||
if (process.env.NR_TRACE && msg.stack) { | ||
console.warn(msg.stack) | ||
} | ||
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 'login' to log in."); | ||
} else if (msg.response.data) { | ||
console.warn(colors.magenta(msg.response.status+": "+msg.response.data.message)); | ||
if (msg.response.status === 404 && !msg.response.data.message) { | ||
console.warn("Node-RED Admin API not found. Use 'target' to set API location"); | ||
} else { | ||
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" : "") + | ||
@@ -175,0 +183,0 @@ " -h|? --help display this help text and exit"; |
{ | ||
"name": "node-red-admin", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "The Node-RED admin command line interface", | ||
@@ -34,3 +34,2 @@ "homepage": "http://nodered.org", | ||
"cli-table": "^0.3.1", | ||
"colors": "^1.4.0", | ||
"minimist": "^1.2.5", | ||
@@ -37,0 +36,0 @@ "read": "^1.0.7" |
@@ -16,3 +16,2 @@ /** | ||
**/ | ||
var colors = require("colors"); | ||
var sinon = require("sinon"); | ||
@@ -19,0 +18,0 @@ var result = require("../../../lib/result"); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6
1883
89135
14
- Removedcolors@^1.4.0
- Removedcolors@1.4.0(transitive)