From 2eb189323355dcf374781aeb1089bff10f1aa915 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Tue, 2 Feb 2016 11:16:30 -0800 Subject: [PATCH 1/9] Add --help and --version command line args Fixes #378 --- package.json | 3 ++- src/vs/workbench/electron-main/bootstrap.js | 26 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index f753567ccfeb2..67a16063e88a9 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,8 @@ "typescript": "^1.7.3", "uglify-js": "2.4.8", "underscore": "^1.8.2", - "vinyl": "^0.4.5" + "vinyl": "^0.4.5", + "yargs": "^3.32.0" }, "repository": { "type": "git", diff --git a/src/vs/workbench/electron-main/bootstrap.js b/src/vs/workbench/electron-main/bootstrap.js index cd37de3705486..868a52c216e1b 100644 --- a/src/vs/workbench/electron-main/bootstrap.js +++ b/src/vs/workbench/electron-main/bootstrap.js @@ -10,6 +10,7 @@ global.vscodeStart = Date.now(); var app = require('electron').app; var path = require('path'); +var process = require('process'); var fs = require('fs'); // Change cwd if given via env variable @@ -19,6 +20,31 @@ try { // noop } +function parseArgs() { + var executable = 'code' + (os.platform() == 'win32' ? '.exe' : ''); + var options = require('yargs')(process.argv.slice(1)); + options.usage( + 'Visual Studio Code v' + app.getVersion() + '\n' + + '\n' + + 'Usage: ' + executable + ' [arguments] [path]'); + options.alias('h', 'help').boolean('h').describe('h', 'Print usage.'); + options.string('locale').describe('locale', 'Use a specific locale.'); + options.boolean('n').describe('n', 'Force a new instance of code.'); + options.alias('v', 'version').boolean('v').describe('v', 'Print version.'); + + var args = options.argv; + if (args.help) { + process.stdout.write(options.help()); + process.exit(0); + } + if (args.version) { + process.stdout.write(app.getVersion()); + process.exit(0); + } +} + +parseArgs(); + // Set path according to being built or not if (!!process.env.VSCODE_DEV) { var appData = app.getPath('appData'); From 1191e340bf8092b2712b68122d409f98fac708a8 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Tue, 2 Feb 2016 14:03:12 -0800 Subject: [PATCH 2/9] Move yargs to non-dev deps --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 67a16063e88a9..515ba4ddf95bc 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "native-keymap": "^0.1.2", "weak": "^1.0.1", "winreg": "0.0.12", + "yargs": "^3.32.0", "yauzl": "^2.3.1" }, "devDependencies": { @@ -85,8 +86,7 @@ "typescript": "^1.7.3", "uglify-js": "2.4.8", "underscore": "^1.8.2", - "vinyl": "^0.4.5", - "yargs": "^3.32.0" + "vinyl": "^0.4.5" }, "repository": { "type": "git", From 1ba5d60b338cb52207e2c5b40e7723dfc7299f63 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Wed, 3 Feb 2016 11:44:20 -0800 Subject: [PATCH 3/9] Fix missing os module in bootstrap.js --- src/vs/workbench/electron-main/bootstrap.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/electron-main/bootstrap.js b/src/vs/workbench/electron-main/bootstrap.js index 868a52c216e1b..14f9a0801b386 100644 --- a/src/vs/workbench/electron-main/bootstrap.js +++ b/src/vs/workbench/electron-main/bootstrap.js @@ -11,6 +11,7 @@ global.vscodeStart = Date.now(); var app = require('electron').app; var path = require('path'); var process = require('process'); +var os = require('os'); var fs = require('fs'); // Change cwd if given via env variable @@ -132,4 +133,4 @@ app.once('ready', function() { loader(['vs/workbench/electron-main/main'], function(main) { // Loading done }, function (err) { console.error(err); }); -}); \ No newline at end of file +}); From 8981819a33a5f085247958553e919e7e9d3c0976 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Wed, 3 Feb 2016 12:14:45 -0800 Subject: [PATCH 4/9] Add Linux/OSX wrapper script This script wraps the main code executable for Linux and OS X, redirecting output to a file and running in the background. An exception is made when help or version argument are used, not suppressing the output as the bootstrap.js is expected to write to stdout and immediately exit. Fixes #77 --- resources/common/bin/code.sh | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 resources/common/bin/code.sh diff --git a/resources/common/bin/code.sh b/resources/common/bin/code.sh new file mode 100755 index 0000000000000..1908d9cb7529b --- /dev/null +++ b/resources/common/bin/code.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +VSCODE_CWD=$(pwd) + +while getopts ":hv-:" opt; do + case $opt in + -) + case $OPTARG in + help|version) + ENABLE_OUTPUT=1 + ;; + esac + ;; + h|v) + ENABLE_OUTPUT=1 + ;; + esac +done + +if [[ "$OSTYPE" == "darwin"* ]]; then + if [ $ENABLE_OUTPUT ]; then + if [ -x "/Applications/Visual Studio Code.app" ]; then + VSCODE_PATH="/Applications/Visual Studio Code.app" + elif [ -x "$HOME/Applications/Visual Studio Code.app" ]; then + VSCODE_PATH="$HOME/Applications/Visual Studio Code.app" + else + echo "Could not locate Visual Studio Code.app" + exit 1 + fi + "$VSCODE_PATH/Contents/MacOS/Electron" "$@" + else + open -n -b "com.microsoft.VSCode" --args $* + fi +else + VSCODE_PATH="/usr/share/code/Code" + if [ -x $VSCODE_PATH ]; then + if [ $ENABLE_OUTPUT ]; then + "$VSCODE_PATH" "$@" + exit $? + else + nohup $VSCODE_PATH "$@" > ~/.vscode/nohup.out 2>&1 & + fi + else + echo "Could not locate Visual Studio Code executable." + exit 1 + fi +fi From 4f29ab242fa0e6c9e08d78f8557a850cd191ed2f Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Thu, 4 Feb 2016 10:10:29 -0800 Subject: [PATCH 5/9] Add trailing new line to -v output --- src/vs/workbench/electron-main/bootstrap.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vs/workbench/electron-main/bootstrap.js b/src/vs/workbench/electron-main/bootstrap.js index 14f9a0801b386..23272ae01b8f3 100644 --- a/src/vs/workbench/electron-main/bootstrap.js +++ b/src/vs/workbench/electron-main/bootstrap.js @@ -39,7 +39,7 @@ function parseArgs() { process.exit(0); } if (args.version) { - process.stdout.write(app.getVersion()); + process.stdout.write(app.getVersion() + '\n'); process.exit(0); } } From f71475856ba3c8c78245dc64f5ad23410fbe5135 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Thu, 4 Feb 2016 11:03:13 -0800 Subject: [PATCH 6/9] Add yargs@^3.32.0 to shrinkwrap --- npm-shrinkwrap.json | 120 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 2123f3ba4b9bf..12cad7573a58c 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -459,6 +459,126 @@ "from": "winreg@0.0.12", "resolved": "https://registry.npmjs.org/winreg/-/winreg-0.0.12.tgz" }, + "yargs": { + "version": "3.32.0", + "from": "yargs@latest", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-3.32.0.tgz", + "dependencies": { + "camelcase": { + "version": "2.1.0", + "from": "camelcase@>=2.0.1 <3.0.0", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-2.1.0.tgz" + }, + "cliui": { + "version": "3.1.0", + "from": "cliui@>=3.0.3 <4.0.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-3.1.0.tgz", + "dependencies": { + "strip-ansi": { + "version": "3.0.0", + "from": "strip-ansi@>=3.0.0 <4.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.0.tgz", + "dependencies": { + "ansi-regex": { + "version": "2.0.0", + "from": "ansi-regex@>=2.0.0 <3.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.0.0.tgz" + } + } + }, + "wrap-ansi": { + "version": "1.0.0", + "from": "wrap-ansi@>=1.0.0 <2.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-1.0.0.tgz" + } + } + }, + "decamelize": { + "version": "1.1.2", + "from": "decamelize@>=1.1.1 <2.0.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.1.2.tgz", + "dependencies": { + "escape-string-regexp": { + "version": "1.0.4", + "from": "escape-string-regexp@>=1.0.4 <2.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.4.tgz" + } + } + }, + "os-locale": { + "version": "1.4.0", + "from": "os-locale@>=1.4.0 <2.0.0", + "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz", + "dependencies": { + "lcid": { + "version": "1.0.0", + "from": "lcid@>=1.0.0 <2.0.0", + "resolved": "https://registry.npmjs.org/lcid/-/lcid-1.0.0.tgz", + "dependencies": { + "invert-kv": { + "version": "1.0.0", + "from": "invert-kv@>=1.0.0 <2.0.0", + "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-1.0.0.tgz" + } + } + } + } + }, + "string-width": { + "version": "1.0.1", + "from": "string-width@>=1.0.1 <2.0.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.1.tgz", + "dependencies": { + "code-point-at": { + "version": "1.0.0", + "from": "code-point-at@>=1.0.0 <2.0.0", + "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.0.0.tgz", + "dependencies": { + "number-is-nan": { + "version": "1.0.0", + "from": "number-is-nan@>=1.0.0 <2.0.0", + "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.0.tgz" + } + } + }, + "is-fullwidth-code-point": { + "version": "1.0.0", + "from": "is-fullwidth-code-point@>=1.0.0 <2.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", + "dependencies": { + "number-is-nan": { + "version": "1.0.0", + "from": "number-is-nan@>=1.0.0 <2.0.0", + "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.0.tgz" + } + } + }, + "strip-ansi": { + "version": "3.0.0", + "from": "strip-ansi@>=3.0.0 <4.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.0.tgz", + "dependencies": { + "ansi-regex": { + "version": "2.0.0", + "from": "ansi-regex@>=2.0.0 <3.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.0.0.tgz" + } + } + } + } + }, + "window-size": { + "version": "0.1.4", + "from": "window-size@>=0.1.4 <0.2.0", + "resolved": "https://registry.npmjs.org/window-size/-/window-size-0.1.4.tgz" + }, + "y18n": { + "version": "3.2.0", + "from": "y18n@>=3.2.0 <4.0.0", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-3.2.0.tgz" + } + } + }, "yauzl": { "version": "2.3.1", "from": "yauzl@>=2.3.1 <3.0.0", From 84ca9b76c76405ec03be1f2c5f444bf9b4d9f57d Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Mon, 8 Feb 2016 21:59:49 -0800 Subject: [PATCH 7/9] Move arg parsing to launcher.js --- resources/common/bin/code.sh | 56 ++++++++------------- resources/common/bin/launcher.js | 47 +++++++++++++++++ src/vs/workbench/electron-main/bootstrap.js | 27 ---------- 3 files changed, 68 insertions(+), 62 deletions(-) create mode 100644 resources/common/bin/launcher.js diff --git a/resources/common/bin/code.sh b/resources/common/bin/code.sh index 1908d9cb7529b..72ab09ff3fcf7 100755 --- a/resources/common/bin/code.sh +++ b/resources/common/bin/code.sh @@ -1,46 +1,32 @@ #!/usr/bin/env bash -VSCODE_CWD=$(pwd) - -while getopts ":hv-:" opt; do - case $opt in - -) - case $OPTARG in - help|version) - ENABLE_OUTPUT=1 - ;; - esac - ;; - h|v) - ENABLE_OUTPUT=1 - ;; - esac -done +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. if [[ "$OSTYPE" == "darwin"* ]]; then - if [ $ENABLE_OUTPUT ]; then - if [ -x "/Applications/Visual Studio Code.app" ]; then - VSCODE_PATH="/Applications/Visual Studio Code.app" - elif [ -x "$HOME/Applications/Visual Studio Code.app" ]; then - VSCODE_PATH="$HOME/Applications/Visual Studio Code.app" - else - echo "Could not locate Visual Studio Code.app" - exit 1 - fi - "$VSCODE_PATH/Contents/MacOS/Electron" "$@" + if [ -x "/Applications/Visual Studio Code.app" ]; then + VSCODE_DIR="/Applications/Visual Studio Code.app/Contents/MacOS" + elif [ -x "$HOME/Applications/Visual Studio Code.app" ]; then + VSCODE_DIR="$HOME/Applications/Visual Studio Code.app/Contents/MacOS" else - open -n -b "com.microsoft.VSCode" --args $* + echo "Could not locate Visual Studio Code.app" + exit 1 fi + ELECTRON_FILE="Electron" else - VSCODE_PATH="/usr/share/code/Code" - if [ -x $VSCODE_PATH ]; then - if [ $ENABLE_OUTPUT ]; then - "$VSCODE_PATH" "$@" - exit $? - else - nohup $VSCODE_PATH "$@" > ~/.vscode/nohup.out 2>&1 & - fi + VSCODE_DIR="/usr/share/code" + if [ -x "$VSCODE_DIR/Code" ]; then + ELECTRON_FILE="Code" + elif [ -x "$VSCODE_DIR/Code - OSS" ]; then + ELECTRON_FILE="Code - OSS" else echo "Could not locate Visual Studio Code executable." exit 1 fi fi + +VSCODE_LAUNCHER="$VSCODE_DIR/launcher.js" + +ATOM_SHELL_INTERNAL_RUN_AS_NODE=1 VSCODE_PATH="$VSCODE_DIR/$ELECTRON_FILE" \ + "$VSCODE_DIR/$ELECTRON_FILE" $VSCODE_LAUNCHER "$@" +exit $? diff --git a/resources/common/bin/launcher.js b/resources/common/bin/launcher.js new file mode 100644 index 0000000000000..d69f1b39f901a --- /dev/null +++ b/resources/common/bin/launcher.js @@ -0,0 +1,47 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +/* global process */ + +var packageJson = require('../../../package.json'); +var os = require('os'); +var spawn = require('child_process').spawn; +var yargs = require('yargs'); + +function parseArgs() { + var executable = 'code' + (os.platform() == 'win32' ? '.exe' : ''); + var options = yargs(process.argv.slice(1)); + options.usage( + 'Visual Studio Code v' + packageJson.version + '\n' + + '\n' + + 'Usage: ' + executable + ' [arguments] [path]'); + options.alias('h', 'help').boolean('h').describe('h', 'Print usage.'); + options.string('locale').describe('locale', 'Use a specific locale.'); + options.boolean('n').describe('n', 'Force a new instance of code.'); + options.alias('v', 'version').boolean('v').describe('v', 'Print version.'); + + var args = options.argv; + if (args.help) { + process.stdout.write(options.help()); + process.exit(0); + } + if (args.version) { + process.stdout.write(packageJson.version + '\n'); + process.exit(0); + } +} + +function launchCode() { + delete process.env['ATOM_SHELL_INTERNAL_RUN_AS_NODE']; + spawn(process.env['VSCODE_PATH'], process.argv.slice(2), { detached: true, stdio: 'ignore' }); +} + +function main() { + parseArgs(); + launchCode(); + process.exit(0); +} + +main(); diff --git a/src/vs/workbench/electron-main/bootstrap.js b/src/vs/workbench/electron-main/bootstrap.js index 23272ae01b8f3..2cffa36b26112 100644 --- a/src/vs/workbench/electron-main/bootstrap.js +++ b/src/vs/workbench/electron-main/bootstrap.js @@ -10,8 +10,6 @@ global.vscodeStart = Date.now(); var app = require('electron').app; var path = require('path'); -var process = require('process'); -var os = require('os'); var fs = require('fs'); // Change cwd if given via env variable @@ -21,31 +19,6 @@ try { // noop } -function parseArgs() { - var executable = 'code' + (os.platform() == 'win32' ? '.exe' : ''); - var options = require('yargs')(process.argv.slice(1)); - options.usage( - 'Visual Studio Code v' + app.getVersion() + '\n' + - '\n' + - 'Usage: ' + executable + ' [arguments] [path]'); - options.alias('h', 'help').boolean('h').describe('h', 'Print usage.'); - options.string('locale').describe('locale', 'Use a specific locale.'); - options.boolean('n').describe('n', 'Force a new instance of code.'); - options.alias('v', 'version').boolean('v').describe('v', 'Print version.'); - - var args = options.argv; - if (args.help) { - process.stdout.write(options.help()); - process.exit(0); - } - if (args.version) { - process.stdout.write(app.getVersion() + '\n'); - process.exit(0); - } -} - -parseArgs(); - // Set path according to being built or not if (!!process.env.VSCODE_DEV) { var appData = app.getPath('appData'); From aedd9ecd9e19b0faab999e27483b3c6da2be190f Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Tue, 9 Feb 2016 11:14:04 -0800 Subject: [PATCH 8/9] Revert "Add yargs@^3.32.0 to shrinkwrap" This reverts commit f71475856ba3c8c78245dc64f5ad23410fbe5135. --- npm-shrinkwrap.json | 120 -------------------------------------------- 1 file changed, 120 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 4782558d99fe2..f440bdba4d999 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -471,126 +471,6 @@ "from": "winreg@0.0.12", "resolved": "https://registry.npmjs.org/winreg/-/winreg-0.0.12.tgz" }, - "yargs": { - "version": "3.32.0", - "from": "yargs@latest", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-3.32.0.tgz", - "dependencies": { - "camelcase": { - "version": "2.1.0", - "from": "camelcase@>=2.0.1 <3.0.0", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-2.1.0.tgz" - }, - "cliui": { - "version": "3.1.0", - "from": "cliui@>=3.0.3 <4.0.0", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-3.1.0.tgz", - "dependencies": { - "strip-ansi": { - "version": "3.0.0", - "from": "strip-ansi@>=3.0.0 <4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.0.tgz", - "dependencies": { - "ansi-regex": { - "version": "2.0.0", - "from": "ansi-regex@>=2.0.0 <3.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.0.0.tgz" - } - } - }, - "wrap-ansi": { - "version": "1.0.0", - "from": "wrap-ansi@>=1.0.0 <2.0.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-1.0.0.tgz" - } - } - }, - "decamelize": { - "version": "1.1.2", - "from": "decamelize@>=1.1.1 <2.0.0", - "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.1.2.tgz", - "dependencies": { - "escape-string-regexp": { - "version": "1.0.4", - "from": "escape-string-regexp@>=1.0.4 <2.0.0", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.4.tgz" - } - } - }, - "os-locale": { - "version": "1.4.0", - "from": "os-locale@>=1.4.0 <2.0.0", - "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz", - "dependencies": { - "lcid": { - "version": "1.0.0", - "from": "lcid@>=1.0.0 <2.0.0", - "resolved": "https://registry.npmjs.org/lcid/-/lcid-1.0.0.tgz", - "dependencies": { - "invert-kv": { - "version": "1.0.0", - "from": "invert-kv@>=1.0.0 <2.0.0", - "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-1.0.0.tgz" - } - } - } - } - }, - "string-width": { - "version": "1.0.1", - "from": "string-width@>=1.0.1 <2.0.0", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.1.tgz", - "dependencies": { - "code-point-at": { - "version": "1.0.0", - "from": "code-point-at@>=1.0.0 <2.0.0", - "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.0.0.tgz", - "dependencies": { - "number-is-nan": { - "version": "1.0.0", - "from": "number-is-nan@>=1.0.0 <2.0.0", - "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.0.tgz" - } - } - }, - "is-fullwidth-code-point": { - "version": "1.0.0", - "from": "is-fullwidth-code-point@>=1.0.0 <2.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", - "dependencies": { - "number-is-nan": { - "version": "1.0.0", - "from": "number-is-nan@>=1.0.0 <2.0.0", - "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.0.tgz" - } - } - }, - "strip-ansi": { - "version": "3.0.0", - "from": "strip-ansi@>=3.0.0 <4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.0.tgz", - "dependencies": { - "ansi-regex": { - "version": "2.0.0", - "from": "ansi-regex@>=2.0.0 <3.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.0.0.tgz" - } - } - } - } - }, - "window-size": { - "version": "0.1.4", - "from": "window-size@>=0.1.4 <0.2.0", - "resolved": "https://registry.npmjs.org/window-size/-/window-size-0.1.4.tgz" - }, - "y18n": { - "version": "3.2.0", - "from": "y18n@>=3.2.0 <4.0.0", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-3.2.0.tgz" - } - } - }, "yauzl": { "version": "2.3.1", "from": "yauzl@>=2.3.1 <3.0.0", From 1d24e7016b4ac7ab406ad59f426e2094acb79843 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Tue, 9 Feb 2016 11:15:05 -0800 Subject: [PATCH 9/9] Remove yargs, roll own arg parser --- package.json | 1 - resources/common/bin/launcher.js | 41 ++++++++++++++++++++------------ 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 17bd4c76323da..2ed9882f44270 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,6 @@ "native-keymap": "^0.1.2", "weak": "^1.0.1", "winreg": "0.0.12", - "yargs": "^3.32.0", "yauzl": "^2.3.1" }, "devDependencies": { diff --git a/resources/common/bin/launcher.js b/resources/common/bin/launcher.js index d69f1b39f901a..bcfc0d26fac82 100644 --- a/resources/common/bin/launcher.js +++ b/resources/common/bin/launcher.js @@ -8,27 +8,38 @@ var packageJson = require('../../../package.json'); var os = require('os'); var spawn = require('child_process').spawn; -var yargs = require('yargs'); -function parseArgs() { +function ArgParser(args) { + this.args = args; +} + +ArgParser.prototype.hasFlag = function (flag, alias) { + return (flag && this.args.indexOf('--' + flag) >= 0) || + (alias && this.args.indexOf('-' + alias) >= 0); +} + +ArgParser.prototype.printHelp = function () { var executable = 'code' + (os.platform() == 'win32' ? '.exe' : ''); - var options = yargs(process.argv.slice(1)); - options.usage( + console.log( 'Visual Studio Code v' + packageJson.version + '\n' + '\n' + - 'Usage: ' + executable + ' [arguments] [path]'); - options.alias('h', 'help').boolean('h').describe('h', 'Print usage.'); - options.string('locale').describe('locale', 'Use a specific locale.'); - options.boolean('n').describe('n', 'Force a new instance of code.'); - options.alias('v', 'version').boolean('v').describe('v', 'Print version.'); - - var args = options.argv; - if (args.help) { - process.stdout.write(options.help()); + 'Usage: ' + executable + ' [arguments] [paths...]\n' + + '\n' + + 'Options:\n' + + ' -h, --help Print usage.\n' + + ' --locale Use a specific locale.\n' + + ' -n Force a new instance of code.\n' + + ' -v, --version Print version.'); +} + +function parseArgs() { + var argParser = new ArgParser(process.argv.slice(2)); + if (argParser.hasFlag('help', 'h')) { + argParser.printHelp(); process.exit(0); } - if (args.version) { - process.stdout.write(packageJson.version + '\n'); + if (argParser.hasFlag('version', 'v')) { + console.log(packageJson.version); process.exit(0); } }