diff --git a/bin/cli.js b/bin/cli.js index 69f8ad3..9ac8936 100644 --- a/bin/cli.js +++ b/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 + // oauth3.js help (alias of `oauth3.js --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, {