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 = {};
function getHelpMessage() {
const help = new dashdash.Parser(
{
options: generalOptions
.concat(converstionOptions)
.concat({ group: "combine (additional options)" })
.concat(combineOptions)
}
).help();
return `usage: any-json [command] FILE [options] [OUT_FILE]
any-json can be used to convert (almost) anything to JSON.
This version supports:
cson, csv, hjson, ini, json, json5, toml, yaml
This version has is beta support for:
xls, xlsx
if (options._args.length > 2) {
throw "too many arguments";
}
const fileName = options._args[0] as string;
const format = options.input_format || getFormatFromFileName(fileName);
const fileContents = await readFile(fileName, anyjson.getEncoding(format))
const parsed = await anyjson.decode(fileContents, format)
const outputFileName = options._args[1]
return await convert(parsed, options, outputFileName);
}
case "combine": {
const parser = new dashdash.Parser(combineConfiguration)
const options = parser.parse({ argv, slice: 3 });
const items = await Promise.all(
options._args.map(async fileName => {
const format = options.input_format || getFormatFromFileName(fileName);
const fileContents = await readFile(fileName, anyjson.getEncoding(format)) as string
return await anyjson.decode(fileContents, format)
})
)
const outputFileName = options.out;
return await convert(items, options, outputFileName);
}
case "split": {
const parser = dashdash.createParser(convertConfiguration);
Cmdln.prototype._renderHelp = function _renderHelp(template, handler, alias) {
assert.string(template, 'template');
assert.optionalString(alias, 'alias');
var help = this._renderTemplate(template, alias);
if (~help.indexOf('{{usage}}')) {
var synopses = this.synopsesFromSubcmd(alias || handler);
if (synopses.length) {
help = help.replace('{{usage}}',
'Usage:\n' + indent(synopses.join('\n')));
}
}
if (~help.indexOf('{{options}}') && handler.options) {
var parser = new dashdash.Parser({options: handler.options});
var helpOpts = (handler.helpOpts
? objMerge(this.helpOpts, handler.helpOpts)
: this.helpOpts);
help = help.replace('{{options}}',
'Options:\n' + parser.help(helpOpts));
}
help = help.trimRight();
return help;
};
Cmdln.prototype.helpFromSubcmd = function helpFromSubcmd(alias) {
var handler = this.handlerFromSubcmd(alias);
if (!handler) {
throw new UnknownCommandError(alias);
}
if (!handler.help) {
return;
} else if (typeof (handler.help) === 'function') {
return handler.help;
} else {
var help = handler.help;
help = help.replace(/{{name}}/g, this.name);
help = help.replace(/{{cmd}}/g, alias);
if (~help.indexOf('{{options}}') && handler.options) {
var parser = new dashdash.Parser({options: handler.options});
var helpOpts = (handler.helpOpts
? objMerge(this.helpOpts, handler.helpOpts) : this.helpOpts);
help = help.replace('{{options}}',
'Options:\n' + parser.help(helpOpts));
}
help = help.trimRight();
return help;
}
};