From 7d51dea35d276983d7c8c13e42119c78581570ef Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Fri, 25 Nov 2016 12:56:54 -0400 Subject: [PATCH] fix(CLI): always omit first two elements of process.argv (#891) This is a great simplification to the logic previously included in the Yargs `.parse()` function on the Etcher CLI. There is no scenario where the CLI script will be executed in a standalone fashion (e.g: `etcher.js `), so we can always safely drop the first two elements from `process.argv`. Change-Type: patch Changelog-Entry: Fix command line arguments not interpreted correctly when running the CLI with a custom named NodeJS binary. Signed-off-by: Juan Cruz Viotti --- lib/cli/cli.js | 37 +------------------------------------ 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/lib/cli/cli.js b/lib/cli/cli.js index 2cc0d12a..72fa2155 100644 --- a/lib/cli/cli.js +++ b/lib/cli/cli.js @@ -18,7 +18,6 @@ const _ = require('lodash'); const fs = require('fs'); -const path = require('path'); const yargs = require('yargs'); const utils = require('./utils'); const EXIT_CODES = require('../src/exit-codes'); @@ -123,38 +122,4 @@ module.exports = yargs default: true } }) - - // Make sure arguments are parsed correctly when running - // in development mode (or NPM) and in a final package. - // - // We rely on the following heuristics to determine if the - // Etcher CLI is being run as a final packaged executable - // or by a tool passing the script as an argument: - .parse(_.attempt((argv) => { - - // Excluding the extension makes sure we cover cases - // like *.exe and *.cmd in Windows systems. - const executable = path.basename(argv[0], path.extname(argv[0])).toLowerCase(); - - if (_.includes([ - 'node', - 'electron', - 'electron helper' - ], executable)) { - - // In this case, the second argument (e.g: index 1) - // equals `lib/cli/etcher.js`, so the real arguments - // start from the third one. - return argv.slice(2); - - } - - // Handle the case where the CLI is executed by pointing - // the packaged electron `Etcher` binary to the application - // asar archive by using `ELECTRON_RUN_AS_NODE`. - if (argv[1] && path.basename(argv[1]) === 'app.asar') { - return argv.slice(2); - } - - return argv.slice(1); - }, process.argv)); + .parse(process.argv.slice(2));