From d89112173df7de01de3db3334a0f096530025fce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Sun, 10 Dec 2017 16:57:26 -0500 Subject: [PATCH] Fix command line index parsing options (`--home` and `--config`) twice --- src/command-line/index.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/command-line/index.js b/src/command-line/index.js index b0e2c04b..beef8bef 100644 --- a/src/command-line/index.js +++ b/src/command-line/index.js @@ -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", Utils.parseConfigOptions ) - .on("--help", Utils.extraHelp) - .parseOptions(process.argv); + .on("--help", Utils.extraHelp); + +// Parse options from `argv` returning `argv` void of these options. +const argvWithoutOptions = program.parseOptions(process.argv); if (program.home) { - log.warn(`${colors.green("--home")} is ${colors.bold.red("deprecated")} and will be removed in The Lounge v3.`); - log.warn(`Use the ${colors.green("THELOUNGE_HOME")} environment variable instead.`); + 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.`); } // 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"; } -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) { program.help();