Skip to content

Commit 1c7f7ae

Browse files
committed
Ensure node-red-admin has non-0 return code when commands fail
1 parent c52fc20 commit 1c7f7ae

File tree

17 files changed

+117
-107
lines changed

17 files changed

+117
-107
lines changed

lib/commands/disable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function command(argv,result) {
2626
data: {
2727
enabled: false
2828
}
29-
}).then(result.logList).catch(result.warn);
29+
}).then(result.logList);
3030
}
3131
command.alias = "disable";
3232
command.usage = command.alias+" {module|id}";

lib/commands/enable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function command(argv,result) {
2626
data: {
2727
enabled: true
2828
}
29-
}).then(result.logList).catch(result.warn);
29+
}).then(result.logList);
3030
}
3131
command.alias = "enable";
3232
command.usage = command.alias+" {module|id}";

lib/commands/info.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function command(argv,result) {
2121
if (!node) {
2222
return result.help(command);
2323
}
24-
return request.request('/nodes/' + node, {}).then(result.logDetails).catch(result.warn);
24+
return request.request('/nodes/' + node, {}).then(result.logDetails);
2525
}
2626
command.alias = "info";
2727
command.usage = command.alias+" {module|node}";

lib/commands/install.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function command(argv,result) {
3737
return request.request('/nodes', {
3838
method: "POST",
3939
data: data
40-
}).then(result.logDetails).catch(result.warn);
40+
}).then(result.logDetails);
4141
}
4242
command.alias = "install";
4343
command.usage = command.alias+" <module> [<url>]";

lib/commands/list.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
var request = require("../request");
1818

1919
function command(argv,result) {
20-
return request.request('/nodes', {}).then(result.logNodeList).catch(result.warn);
20+
return request.request('/nodes', {}).then(result.logNodeList);
2121
}
2222
command.alias = "list";
2323
command.usage = command.alias;

lib/commands/login.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,42 +20,42 @@ var prompt = require("../prompt");
2020

2121
function command(argv,result) {
2222
config.tokens(null);
23-
if (argv.json) {
24-
console.warn("login command does not support json format output");
25-
}
2623
return request.request('/auth/login',{}).then(function(resp) {
27-
if (resp.type) {
28-
if (resp.type == "credentials") {
29-
prompt.read({prompt:"Username:"},function(err, username) {
30-
prompt.read({prompt:"Password:",silent: true},function(err, password) {
31-
request.request('/auth/token', {
32-
method: "POST",
33-
data: {
34-
client_id: 'node-red-admin',
35-
grant_type: 'password',
36-
scope: '*',
37-
username: username,
38-
password: password
39-
}
40-
}).then(function(resp) {
41-
config.tokens(resp);
42-
result.log("Logged in");
43-
}).catch(function(resp) {
44-
result.warn("Login failed");
24+
return new Promise((resolve,reject) => {
25+
if (resp.type) {
26+
if (resp.type == "credentials") {
27+
prompt.read({prompt:"Username:"},function(err, username) {
28+
prompt.read({prompt:"Password:",silent: true},function(err, password) {
29+
request.request('/auth/token', {
30+
method: "POST",
31+
data: {
32+
client_id: 'node-red-admin',
33+
grant_type: 'password',
34+
scope: '*',
35+
username: username,
36+
password: password
37+
}
38+
}).then(function(resp) {
39+
config.tokens(resp);
40+
result.log("Logged in");
41+
resolve();
42+
}).catch(function(resp) {
43+
reject("Login failed");
44+
});
4545
});
4646
});
47-
});
47+
} else {
48+
reject("Unsupported login type");
49+
}
4850
} else {
49-
result.warn("Unsupported login type");
51+
resolve();
5052
}
51-
}
52-
}).catch(function(resp) {
53-
result.warn("Login failed");
53+
});
5454
});
5555
}
5656

5757
command.alias = "login";
5858
command.usage = command.alias+"";
59-
command.description = "Log user in to the targetted Node-RED admin api";
59+
command.description = "Log in to the targetted Node-RED admin api";
6060

6161
module.exports = command;

lib/commands/projects.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
var request = require("../request");
1818

1919
function command(argv,result) {
20-
return request.request('/projects', {}).then(result.logProjectList).catch(result.warn);
20+
return request.request('/projects', {}).then(result.logProjectList);
2121
}
2222
command.alias = "projects";
2323
command.usage = command.alias;

lib/commands/remove.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function command(argv,result) {
2929
} else {
3030
result.log("Uninstalled " + module);
3131
}
32-
}).catch(result.warn);
32+
});
3333
}
3434
command.alias = "remove";
3535
command.usage = command.alias+" <module>";

lib/commands/search.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,8 @@ function command(argv,result) {
6565
}
6666
}
6767
} else {
68-
result.warn(response.status + ": " + response.data);
68+
throw new Error(response.status + ": " + response.data);
6969
}
70-
}).catch(err => {
71-
result.warn(err.toString());
7270
});
7371

7472
}

lib/commands/target.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,25 @@
1717
var config = require("../config");
1818

1919
function command(argv,result) {
20-
var target = argv._[1];
21-
if (target) {
22-
if (!/^https?:\/\/.+/.test(target)) {
23-
result.warn("Invalid target URL: " + target);
24-
return;
20+
return new Promise((resolve,reject) => {
21+
var target = argv._[1];
22+
if (target) {
23+
if (!/^https?:\/\/.+/.test(target)) {
24+
reject("Invalid target URL: " + target);
25+
return;
26+
}
27+
if (target.slice(-1) == "/") {
28+
target = target.slice(0, target.length - 1);
29+
}
30+
config.target(target);
2531
}
26-
if (target.slice(-1) == "/") {
27-
target = target.slice(0, target.length - 1);
32+
if (argv.json) {
33+
result.log(JSON.stringify({target: config.target()}," ",4));
34+
} else {
35+
result.log("Target: " + config.target());
2836
}
29-
config.target(target);
30-
31-
}
32-
if (argv.json) {
33-
result.log(JSON.stringify({target: config.target()}," ",4));
34-
} else {
35-
result.log("Target: " + config.target());
36-
}
37+
resolve();
38+
});
3739
}
3840

3941
command.alias = "target";

0 commit comments

Comments
 (0)