Unforked the shared modules -- ES6 is now the default
This commit is contained in:
parent
323a42be37
commit
822ab39cbe
108 changed files with 3310 additions and 9776 deletions
|
|
@ -28,59 +28,60 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var proc = {};
|
||||
|
||||
/**
|
||||
* getArgs()
|
||||
*
|
||||
* Processes command-line arguments. Arguments may be introduced by either
|
||||
* a double-hyphen (--) or a long dash (—), and argument values, if any, must be
|
||||
* separated by an "=" without any intervening whitespace. Arguments without
|
||||
* an explicit value default to true, and any argument appearing more than once
|
||||
* is automatically converted to an Array.
|
||||
*
|
||||
* Single-hyphen (-) arguments are allowed as well; they are treated as a series
|
||||
* of single-character arguments, each set to true, and any of these arguments
|
||||
* appearing more than once is discarded.
|
||||
*
|
||||
* @return {{argc:number, argv:{}}}
|
||||
*/
|
||||
proc.getArgs = function() {
|
||||
var argc = 0;
|
||||
var argv = {};
|
||||
for (var i = 2; i < process.argv.length; i++) {
|
||||
var j, sSep;
|
||||
var sArg = process.argv[i];
|
||||
if (!sArg.indexOf(sSep = "--") || !sArg.indexOf(sSep = "—")) {
|
||||
sArg = sArg.substr(sSep.length);
|
||||
var sValue = true;
|
||||
j = sArg.indexOf("=");
|
||||
if (j > 0) {
|
||||
sValue = sArg.substr(j+1);
|
||||
sArg = sArg.substr(0, j);
|
||||
sValue = (sValue == "true")? true : ((sValue == "false")? false : sValue);
|
||||
}
|
||||
if (argv[sArg] === undefined) {
|
||||
argc++;
|
||||
argv[sArg] = sValue;
|
||||
} else {
|
||||
// console.log("too many '" + sArg + "' arguments");
|
||||
if (typeof argv[sArg] == "string") {
|
||||
argv[sArg] = [argv[sArg]];
|
||||
class Proc {
|
||||
/**
|
||||
* getArgs()
|
||||
*
|
||||
* Processes command-line arguments. Arguments may be introduced by either
|
||||
* a double-hyphen (--) or a long dash (—), and argument values, if any, must be
|
||||
* separated by an "=" without any intervening whitespace. Arguments without
|
||||
* an explicit value default to true, and any argument appearing more than once
|
||||
* is automatically converted to an Array.
|
||||
*
|
||||
* Single-hyphen (-) arguments are allowed as well; they are treated as a series
|
||||
* of single-character arguments, each set to true, and any of these arguments
|
||||
* appearing more than once is discarded.
|
||||
*
|
||||
* @return {{argc:number, argv:{}}}
|
||||
*/
|
||||
static getArgs()
|
||||
{
|
||||
var argc = 0;
|
||||
var argv = {};
|
||||
for (var i = 2; i < process.argv.length; i++) {
|
||||
var j, sSep;
|
||||
var sArg = process.argv[i];
|
||||
if (!sArg.indexOf(sSep = "--") || !sArg.indexOf(sSep = "—")) {
|
||||
sArg = sArg.substr(sSep.length);
|
||||
var sValue = true;
|
||||
j = sArg.indexOf("=");
|
||||
if (j > 0) {
|
||||
sValue = sArg.substr(j + 1);
|
||||
sArg = sArg.substr(0, j);
|
||||
sValue = (sValue == "true") ? true : ((sValue == "false") ? false : sValue);
|
||||
}
|
||||
argv[sArg].push(sValue);
|
||||
}
|
||||
} else if (!sArg.indexOf("-")) {
|
||||
for (j = 1; j < sArg.length; j++) {
|
||||
var ch = sArg.charAt(j);
|
||||
if (argv[ch] === undefined) {
|
||||
argv[ch] = true;
|
||||
if (argv[sArg] === undefined) {
|
||||
argc++;
|
||||
argv[sArg] = sValue;
|
||||
} else {
|
||||
// console.log("too many '" + sArg + "' arguments");
|
||||
if (typeof argv[sArg] == "string") {
|
||||
argv[sArg] = [argv[sArg]];
|
||||
}
|
||||
argv[sArg].push(sValue);
|
||||
}
|
||||
} else if (!sArg.indexOf("-")) {
|
||||
for (j = 1; j < sArg.length; j++) {
|
||||
var ch = sArg.charAt(j);
|
||||
if (argv[ch] === undefined) {
|
||||
argv[ch] = true;
|
||||
argc++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return {argc: argc, argv: argv};
|
||||
}
|
||||
return {argc: argc, argv: argv};
|
||||
};
|
||||
}
|
||||
|
||||
if (NODE) module.exports = proc;
|
||||
if (NODE) module.exports = Proc;
|
||||
|
|
|
|||
Loading…
Reference in a new issue