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 sep = /[:\.\-]/;
|
||||
|
||||
args.shift(); // node
|
||||
args.shift(); // oauth3.js
|
||||
args.shift(); // 'node' is the first parameter
|
||||
args.shift(); // 'oauth3.js' will be the
|
||||
|
||||
var command = args.shift() || 'help';
|
||||
var cmdpair = command.split(sep);
|
||||
|
@ -20,12 +20,12 @@ function parseArgs(argv, opts) {
|
|||
var COMMAND = 'COMMAND';
|
||||
var maxCmdLen = COMMAND.length;
|
||||
var maxPairLen = 0;
|
||||
var tlcs; // top-level commands
|
||||
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 = {};
|
||||
tlcs = opts.commands.filter(function (desc) {
|
||||
var tlcs = opts.commands.filter(function (desc) {
|
||||
var pair = desc[0].split(/\s+/)[0];
|
||||
var psub = pair.split(sep)[0];
|
||||
pairsMap[pair] = true;
|
||||
|
@ -36,6 +36,7 @@ function parseArgs(argv, opts) {
|
|||
}
|
||||
});
|
||||
|
||||
// right pad (for making the printed lines longer)
|
||||
function rpad(str, len) {
|
||||
while (str.length < len) {
|
||||
str += ' ';
|
||||
|
@ -43,6 +44,9 @@ function parseArgs(argv, opts) {
|
|||
return str;
|
||||
}
|
||||
|
||||
// oauth3.js help
|
||||
// oauth3.js help <command>
|
||||
// oauth3.js help <command:sub> (alias of `oauth3.js <command:sub> --help')
|
||||
function help() {
|
||||
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)) {
|
||||
arg1 = cmd;
|
||||
cmd = 'help';
|
||||
|
@ -149,12 +154,14 @@ function parseArgs(argv, opts) {
|
|||
return;
|
||||
}
|
||||
|
||||
// If help is explictly requested
|
||||
if (-1 !== [ 'help', '-h', '--help' ].indexOf(command) || -1 !== args.indexOf('-h') || -1 !== args.indexOf('--help')) {
|
||||
help();
|
||||
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, {
|
||||
|
|
Loading…
Reference in New Issue