forked from microsoft/vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request microsoft#2650 from Tyriar/378_add_usage
Add -h/-v command line args and unified launch scripts
- Loading branch information
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# 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 [ -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 | ||
echo "Could not locate Visual Studio Code.app" | ||
exit 1 | ||
fi | ||
ELECTRON_FILE="Electron" | ||
else | ||
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 $? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* 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; | ||
|
||
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' : ''); | ||
console.log( | ||
'Visual Studio Code v' + packageJson.version + '\n' + | ||
'\n' + | ||
'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 (argParser.hasFlag('version', 'v')) { | ||
console.log(packageJson.version); | ||
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(); |