argv.ts 2.7 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

export interface ParsedArgs extends minimist.ParsedArgs {
	help: boolean;
	version: boolean;
	wait: boolean;
J
Joao Moreno 已提交
14 15 16 17 18 19 20 21 22 23
	diff: boolean;
	goto: boolean;
	'new-window': boolean;
	'reuse-window': boolean;
	locale: string;
	'user-data-dir': string;
	performance: boolean;
	verbose: boolean;
	logExtensionHostCommunication: boolean;
	'disable-extensions': boolean;
J
Joao Moreno 已提交
24 25 26 27 28 29
	extensionHomePath: string;
	extensionDevelopmentPath: string;
	extensionTestsPath: string;
	timestamp: string;
	debugBrkPluginHost: string;
	debugPluginHost: string;
J
Joao Moreno 已提交
30 31
}

J
Joao Moreno 已提交
32
const options: minimist.Opts = {
33 34
	string: [
		'locale',
J
Joao Moreno 已提交
35 36 37 38 39
		'user-data-dir',
		'extensionHomePath',
		'extensionDevelopmentPath',
		'extensionTestsPath',
		'timestamp'
40 41 42 43 44 45 46 47
	],
	boolean: [
		'help',
		'version',
		'wait',
		'diff',
		'goto',
		'new-window',
J
Joao Moreno 已提交
48 49 50 51 52
		'reuse-window',
		'performance',
		'verbose',
		'logExtensionHostCommunication',
		'disable-extensions'
53
	],
J
Joao Moreno 已提交
54 55 56
	alias: {
		help: 'h',
		version: 'v',
57 58 59 60
		wait: 'w',
		diff: 'd',
		goto: 'g',
		'new-window': 'n',
J
Joao Moreno 已提交
61 62 63
		'reuse-window': 'r',
		performance: 'p',
		'disable-extensions': 'disableExtensions'
J
Joao Moreno 已提交
64
	}
J
Joao Moreno 已提交
65
};
J
Joao Moreno 已提交
66 67 68

export function parseArgs(args: string[]) {
	return minimist(args, options) as ParsedArgs;
J
Joao Moreno 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
}

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.
J
Joao Moreno 已提交
84
${ indent }--locale <locale>     The locale to use (e.g. en-US or zh-TW).
J
Joao Moreno 已提交
85 86 87
${ 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.
J
Joao Moreno 已提交
88
${ indent }--user-data-dir <dir> Specifies the directory that user data is kept in,
J
Joao Moreno 已提交
89 90 91
${ indent }                      useful when running as root.
${ indent }-v, --version         Print version.
${ indent }-w, --wait            Wait for the window to be closed before returning.`;