Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
args = argv.slice(3);
}
if (typeof (handler.main) === 'function') {
// This is likely a `Cmdln` subclass instance, i.e. a subcli.
(function callCmdlnHandler(subcmd, opts, args, cb) {
var argv = ['', ''].concat(args);
handler.main(argv, cb);
}).call(this, subcmd, opts, args, finish);
} else {
// This is a vanilla `do_SUBCMD` function on the Cmdln class.
// Skip optional processing if given `opts` -- i.e. it was already done.
if (argv && handler.options) {
try {
var parser = new dashdash.Parser({
options: handler.options,
interspersed: (handler.interspersedOptions !== undefined
? handler.interspersedOptions : true),
allowUnknown: (handler.allowUnknownOptions !== undefined
? handler.allowUnknownOptions : false)
});
opts = parser.parse(argv, 3);
} catch (e) {
finish(new OptionError(e));
return;
}
args = opts._args;
debug('-- parse %j opts: %j', subcmd, opts);
}
handler.call(this, subcmd, opts, args, finish);
}
this.helpSubcmds = config.helpSubcmds || null;
if (!this.helpOpts.indent)
this.helpOpts.indent = space(4);
else if (typeof (this.helpOpts.indent) === 'number')
this.helpOpts.indent = space(this.helpOpts.indent);
if (!this.helpOpts.groupIndent) {
var gilen = Math.round(this.helpOpts.indent.length / 2);
this.helpOpts.groupIndent = space(gilen);
} else if (typeof (this.helpOpts.groupIndent) === 'number') {
this.helpOpts.groupIndent = space(this.helpOpts.groupIndent);
}
if (!this.helpOpts.maxCol) this.helpOpts.maxCol = 80;
if (!this.helpOpts.minHelpCol) this.helpOpts.minHelpCol = 20;
if (!this.helpOpts.maxHelpCol) this.helpOpts.maxHelpCol = 40;
this.optParser = new dashdash.Parser(
{options: this.options, interspersed: false});
// Find the tree of constructors (typically just this and the Cmdln
// super class) on who's prototype to look for "do_*" and "help_*"
// methods.
var prototypes = [];
var ctor = this.constructor;
while (ctor) {
prototypes.push(ctor.prototype);
ctor = ctor.super_; // presuming `util.inherits` usage
}
prototypes.reverse();
// Load subcmds (do_* methods) and aliases (`do_*.aliases`).
var enumOrder = [];
this._handlerFromName = {};
this.helpSubcmds = config.helpSubcmds || null;
if (!this.helpOpts.indent)
this.helpOpts.indent = space(4);
else if (typeof (this.helpOpts.indent) === 'number')
this.helpOpts.indent = space(this.helpOpts.indent);
if (!this.helpOpts.groupIndent) {
var gilen = Math.round(this.helpOpts.indent.length / 2);
this.helpOpts.groupIndent = space(gilen);
} else if (typeof (this.helpOpts.groupIndent) === 'number') {
this.helpOpts.groupIndent = space(this.helpOpts.groupIndent);
}
if (!this.helpOpts.maxCol) this.helpOpts.maxCol = 80;
if (!this.helpOpts.minHelpCol) this.helpOpts.minHelpCol = 20;
if (!this.helpOpts.maxHelpCol) this.helpOpts.maxHelpCol = 40;
this.optParser = new dashdash.Parser(
{options: this.options, interspersed: false});
// Find the tree of constructors (typically just this and the Cmdln
// super class) on who's prototype to look for "do_*" and "help_*"
// methods.
var prototypes = [];
var ctor = this.constructor;
while (ctor) {
prototypes.push(ctor.prototype);
ctor = ctor.super_; // presuming `util.inherits` usage
}
prototypes.reverse();
// Load subcmds (do_* methods) and aliases (`do_*.aliases`).
var enumOrder = [];
this._handlerFromName = {};
Cmdln.prototype.bashCompletionSpec = function bashCompletionSpec(opts) {
var self = this;
if (!opts) {
opts = {};
}
assert.object(opts, 'opts');
assert.optionalString(opts.context, 'opts.context');
assert.optionalBool(opts.includeHidden, 'opts.includeHidden');
var spec = [];
var context = opts.context || '';
var includeHidden = (opts.includeHidden === undefined
? false : opts.includeHidden);
// Top-level.
spec.push(dashdash.bashCompletionSpecFromOptions({
options: self.options,
context: context,
includeHidden: includeHidden
}));
var aliases = [];
var allAliases = [];
Object.keys(this._nameFromAlias).sort().forEach(function (alias) {
if (alias === '?') {
// '?' as a Bash completion is painful. Also, '?' as a default
// alias for 'help' should die.
return;
}
var name = self._nameFromAlias[alias];
var handler = self._handlerFromName[name];
var handler = self._handlerFromName[name];
if (typeof (handler.bashCompletionSpec) === 'function') {
// This is a `Cmdln` subclass, i.e. a sub-CLI.
var subspec = handler.bashCompletionSpec({context: context_});
if (subspec) {
spec.push(subspec);
}
} else {
if (handler.completionArgtypes) {
assert.arrayOfString(handler.completionArgtypes,
'do_' + name + '.completionArgtypes');
spec.push(format('local cmd%s_argtypes="%s"',
context_, handler.completionArgtypes.join(' ')));
}
spec.push(dashdash.bashCompletionSpecFromOptions({
options: handler.options || [],
context: context_,
includeHidden: includeHidden
}));
}
});
assert.object(opts, 'opts');
assert.optionalString(opts.specExtra, 'opts.specExtra');
// Gather template data.
var data = {
name: this.name,
date: new Date(),
spec: this.bashCompletionSpec()
};
if (opts.specExtra) {
data.spec += '\n\n' + opts.specExtra;
}
// Render template.
var template = fs.readFileSync(
dashdash.BASH_COMPLETION_TEMPLATE_PATH, 'utf8');
return renderTemplate(template, data);
};
OptionError.prototype.cmdlnErrHelpFromErr = function optionErrHelpFromErr(err) {
if (!err || !err._cmdlnInst) {
return '';
}
var errHelp = '';
var options = (err._cmdlnHandler || err._cmdlnInst).options;
if (options) {
var lines = [];
var line = 'usage: ' + nameFromErr(err);
for (var i = 0; i < options.length; i++) {
var synopsis = dashdash.synopsisFromOpt(options[i]);
if (!synopsis) {
continue;
} else if (line.length === 0) {
line += ' ' + synopsis;
} else if (line.length + synopsis.length + 1 > 80) {
lines.push(line);
line = ' ' + synopsis;
} else {
line += ' ' + synopsis;
}
}
lines.push(line + ' ...'); // The "..." for the args.
errHelp = lines.join('\n');
}
names: ['delay'],
type: 'number',
env: 'DELAY',
help: 'Events handling delay (for temp setup)',
default: 0,
},
{
names: ['stupid'],
type: 'bool',
env: 'STUPID',
help: 'Enables wrong results producing',
default: false,
},
];
const parser = dashdash.createParser({ options });
/**
* @type {{
* ethProvider: string;
* walletPriv: string;
* enforcerAddr: string;
* delay: number;
* stupid: boolean;
* }}
*/
const cliArgs = parser.parse(process.argv);
if (cliArgs.help) {
console.log('Usage:');
console.log(parser.help({ includeEnv: true }).trimRight());
process.exit(0);
var su = require("suman-utils");
var _suman = global.__suman = (global.__suman || {});
require('../helpers/add-suman-global-properties');
var constants = require('../../config/suman-constants').constants;
var fatalRequestReply = require('../helpers/general').fatalRequestReply;
if (process.env.NPM_COLORS === 'no') {
process.argv.push('--no-color');
console.log(' => Suman child process setting itself to be color-free (--no-colors)');
}
var sumanOpts = _suman.sumanOpts = _suman.sumanOpts || JSON.parse(process.env.SUMAN_OPTS);
var suman_options_1 = require("../parse-cmd-line-opts/suman-options");
var childArgs = sumanOpts.child_arg || [];
if (childArgs.length) {
childArgs.unshift('foo');
childArgs.unshift('baz');
var opts = void 0, parser = dashdash.createParser({ options: suman_options_1.options });
try {
opts = parser.parse(childArgs);
}
catch (err) {
console.error(chalk.red(' => Suman command line options error:'), err.message);
console.error(' => Try "suman --help" or visit sumanjs.org');
process.exit(constants.EXIT_CODES.BAD_COMMAND_LINE_OPTION);
}
sumanOpts = _suman.sumanOpts = Object.assign(sumanOpts, opts);
}
var usingRunner = _suman.usingRunner = true;
var projectRoot = _suman.projectRoot = process.env.SUMAN_PROJECT_ROOT;
process.send = process.send || function (data) {
console.error(chalk.magenta('Suman warning:'));
console.error('process.send() was not originally defined in this process.');
console.error('(Perhaps we are using Istanbul?), we are logging the first argument to process.send() here => ');
const Interpreter = require("./interpreter"),
Scopes = require("./scope"),
fs = require("fs"),
dashdash = require("dashdash");
function die(message) {
console.warn(message);
process.exit(1);
}
var optParser = dashdash.createParser({
options: [
{
names:["help", "h"],
type: "bool",
help: "Print usage and exit"
},
{
names:["output", "o"],
type: "string",
help: "Output file",
helpArg: "FILE",
default: "entities.json"
},
{
names: ["check", "c"],
type: "bool",