argv.ts 2.1 KB
Newer Older
J
Joao Moreno 已提交
1 2 3 4 5
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

J
Joao Moreno 已提交
6
import * as os from 'os';
J
Joao Moreno 已提交
7
import * as minimist from 'minimist';
J
Joao Moreno 已提交
8
import pkg from './package';
J
Joao Moreno 已提交
9 10 11 12 13 14 15

export interface ParsedArgs extends minimist.ParsedArgs {
	help: boolean;
	version: boolean;
	wait: boolean;
}

J
Joao Moreno 已提交
16
const options: minimist.Opts = {
17 18 19 20 21 22 23 24 25 26 27 28 29
	string: [
		'locale',
		'user-data-dir'
	],
	boolean: [
		'help',
		'version',
		'wait',
		'diff',
		'goto',
		'new-window',
		'reuse-window'
	],
J
Joao Moreno 已提交
30 31 32
	alias: {
		help: 'h',
		version: 'v',
33 34 35 36 37
		wait: 'w',
		diff: 'd',
		goto: 'g',
		'new-window': 'n',
		'reuse-window': 'r'
J
Joao Moreno 已提交
38
	}
J
Joao Moreno 已提交
39
};
J
Joao Moreno 已提交
40 41 42

export function parseArgs(args: string[]) {
	return minimist(args, options) as ParsedArgs;
J
Joao Moreno 已提交
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
}

const executable = 'code' + (os.platform() === 'win32' ? '.exe' : '');
const indent = '  ';
export const helpMessage = `Visual Studio Code v${ pkg.version }

Usage: ${ executable } [arguments] [paths...]

Options:
${ indent }-d, --diff            Open a diff editor. Requires to pass two file paths
${ indent }                      as arguments.
${ indent }--disable-extensions  Disable all installed extensions.
${ indent }-g, --goto            Open the file at path at the line and column (add
${ indent }                      :line[:column] to path).
${ indent }-h, --help            Print usage.
${ indent }--locale=LOCALE       The locale to use (e.g. en-US or zh-TW).
${ indent }-n, --new-window      Force a new instance of Code.
${ indent }-r, --reuse-window    Force opening a file or folder in the last active
${ indent }                      window.
${ indent }--user-data-dir=DIR   Specifies the directory that user data is kept in,
${ indent }                      useful when running as root.
${ indent }-v, --version         Print version.
${ indent }-w, --wait            Wait for the window to be closed before returning.`;