Fix command line index parsing options (--home and --config) twice

This commit is contained in:
Jérémie Astori 2017-12-10 16:57:26 -05:00
parent 6547d18e7f
commit d89112173d
No known key found for this signature in database
GPG Key ID: B9A4F245CD67BDE8

View File

@ -22,12 +22,13 @@ program.version(Helper.getVersion(), "-v, --version")
"override entries of the configuration file, must be specified for each entry that needs to be overriden", "override entries of the configuration file, must be specified for each entry that needs to be overriden",
Utils.parseConfigOptions Utils.parseConfigOptions
) )
.on("--help", Utils.extraHelp) .on("--help", Utils.extraHelp);
.parseOptions(process.argv);
// Parse options from `argv` returning `argv` void of these options.
const argvWithoutOptions = program.parseOptions(process.argv);
if (program.home) { if (program.home) {
log.warn(`${colors.green("--home")} is ${colors.bold.red("deprecated")} and will be removed in The Lounge v3.`); log.warn(`${colors.bold("--home")} is ${colors.bold.red("deprecated")} and will be removed in The Lounge v3. Use the ${colors.bold("THELOUNGE_HOME")} environment variable instead.`);
log.warn(`Use the ${colors.green("THELOUNGE_HOME")} environment variable instead.`);
} }
// Check if the app was built before calling setHome as it wants to load manifest.json from the public folder // Check if the app was built before calling setHome as it wants to load manifest.json from the public folder
@ -72,7 +73,13 @@ if (process.argv[1].endsWith(`${require("path").sep}lounge`)) {
process.argv[1] = "thelounge"; process.argv[1] = "thelounge";
} }
program.parse(process.argv); // `parse` expects to be passed `process.argv`, but we need to remove to give it
// a version of `argv` that does not contain options already parsed by
// `parseOptions` above.
// This is done by giving it the updated `argv` that `parseOptions` returned,
// except it returns an object with `args`/`unknown`, so we need to concat them.
// See https://github.com/tj/commander.js/blob/fefda77f463292/index.js#L686-L763
program.parse(argvWithoutOptions.args.concat(argvWithoutOptions.unknown));
if (!program.args.length) { if (!program.args.length) {
program.help(); program.help();