added some comments
This commit is contained in:
parent
e99b9ff4d6
commit
19b0e7a5d2
19
bin/cli.js
19
bin/cli.js
|
@ -10,8 +10,8 @@ function parseArgs(argv, opts) {
|
||||||
var args = Array.prototype.slice.call(argv);
|
var args = Array.prototype.slice.call(argv);
|
||||||
var sep = /[:\.\-]/;
|
var sep = /[:\.\-]/;
|
||||||
|
|
||||||
args.shift(); // node
|
args.shift(); // 'node' is the first parameter
|
||||||
args.shift(); // oauth3.js
|
args.shift(); // 'oauth3.js' will be the
|
||||||
|
|
||||||
var command = args.shift() || 'help';
|
var command = args.shift() || 'help';
|
||||||
var cmdpair = command.split(sep);
|
var cmdpair = command.split(sep);
|
||||||
|
@ -20,12 +20,12 @@ function parseArgs(argv, opts) {
|
||||||
var COMMAND = 'COMMAND';
|
var COMMAND = 'COMMAND';
|
||||||
var maxCmdLen = COMMAND.length;
|
var maxCmdLen = COMMAND.length;
|
||||||
var maxPairLen = 0;
|
var maxPairLen = 0;
|
||||||
var tlcs; // top-level commands
|
|
||||||
var arg1 = args[0];
|
var arg1 = args[0];
|
||||||
|
|
||||||
// build commands list
|
// build top-level commands (tlcs) list
|
||||||
|
// also count the word-width (for the space needed to print the commands)
|
||||||
var pairsMap = {};
|
var pairsMap = {};
|
||||||
tlcs = opts.commands.filter(function (desc) {
|
var tlcs = opts.commands.filter(function (desc) {
|
||||||
var pair = desc[0].split(/\s+/)[0];
|
var pair = desc[0].split(/\s+/)[0];
|
||||||
var psub = pair.split(sep)[0];
|
var psub = pair.split(sep)[0];
|
||||||
pairsMap[pair] = true;
|
pairsMap[pair] = true;
|
||||||
|
@ -36,6 +36,7 @@ function parseArgs(argv, opts) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// right pad (for making the printed lines longer)
|
||||||
function rpad(str, len) {
|
function rpad(str, len) {
|
||||||
while (str.length < len) {
|
while (str.length < len) {
|
||||||
str += ' ';
|
str += ' ';
|
||||||
|
@ -43,6 +44,9 @@ function parseArgs(argv, opts) {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// oauth3.js help
|
||||||
|
// oauth3.js help <command>
|
||||||
|
// oauth3.js help <command:sub> (alias of `oauth3.js <command:sub> --help')
|
||||||
function help() {
|
function help() {
|
||||||
var status = 0;
|
var status = 0;
|
||||||
|
|
||||||
|
@ -142,6 +146,7 @@ function parseArgs(argv, opts) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the command is not in the list of commands
|
||||||
if (-1 === Object.keys(pairsMap).indexOf(cmd)) {
|
if (-1 === Object.keys(pairsMap).indexOf(cmd)) {
|
||||||
arg1 = cmd;
|
arg1 = cmd;
|
||||||
cmd = 'help';
|
cmd = 'help';
|
||||||
|
@ -149,12 +154,14 @@ function parseArgs(argv, opts) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If help is explictly requested
|
||||||
if (-1 !== [ 'help', '-h', '--help' ].indexOf(command) || -1 !== args.indexOf('-h') || -1 !== args.indexOf('--help')) {
|
if (-1 !== [ 'help', '-h', '--help' ].indexOf(command) || -1 !== args.indexOf('-h') || -1 !== args.indexOf('--help')) {
|
||||||
help();
|
help();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('RUN', cmd, sub || '(n/a)', arg1 || '(n/a)');
|
// If we're ready to rock and roll!
|
||||||
|
console.log('RUN', cmd, sub || '(n/a)', arg1 || '(n/a)', '... not yet implemented');
|
||||||
}
|
}
|
||||||
|
|
||||||
parseArgs(process.argv, {
|
parseArgs(process.argv, {
|
||||||
|
|
Loading…
Reference in New Issue