fixed console command arg parsing on recovery core
Bryan Roe committed
Jan 17, 2021 at 19:38 UTC
2faede16d46f5df0aa4e80657147c9c4957179ed
1 file changed
+11
-4
agents/recoverycore.js
+11
-4
@@ -103,6 +103,8 @@ function pathjoin()
103
if (x.length == 0) return '/';
104
return x.join('/');
105
}
106
+// Replace a string with a number if the string is an exact number
107
+function toNumberIfNumber(x) { if ((typeof x == 'string') && (+parseInt(x) === x)) { x = parseInt(x); } return x; }
108
109
110
function bsd_execv(name, agentfilename, sessionid)
@@ -381,20 +383,25 @@ function splitArgs(str) {
383
}
384
385
// Parse arguments string array into an object
384
-function parseArgs(argv) {
386
+function parseArgs(argv)
387
+{
388
var results = { '_': [] }, current = null;
386
- for (var i = 1, len = argv.length; i < len; i++) {
389
+ for (var i = 1, len = argv.length; i < len; i++)
390
+ {
391
var x = argv[i];
388
- if (x.length > 2 && x[0] == '-' && x[1] == '-') {
392
+ if (x.length > 2 && x[0] == '-' && x[1] == '-')
393
+ {
394
if (current != null) { results[current] = true; }
395
current = x.substring(2);
391
- } else {
396
+ } else
397
+ {
398
if (current != null) { results[current] = toNumberIfNumber(x); current = null; } else { results['_'].push(toNumberIfNumber(x)); }
399
}
400
}
401
if (current != null) { results[current] = true; }
402
return results;
403
}
404
+
405
// Get server target url with a custom path
406
function getServerTargetUrl(path) {
407
var x = require('MeshAgent').ServerUrl;