Skip to content

Commit 1cab21c

Browse files
committed
make string[] in ParsedArgs consistent
1 parent 7077b6b commit 1cab21c

6 files changed

Lines changed: 54 additions & 76 deletions

File tree

src/vs/code/electron-main/app.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ import { serve as serveDriver } from 'vs/platform/driver/electron-main/driver';
5656
import { IMenubarService } from 'vs/platform/menubar/node/menubar';
5757
import { MenubarService } from 'vs/platform/menubar/electron-main/menubarService';
5858
import { MenubarChannel } from 'vs/platform/menubar/node/menubarIpc';
59-
import { hasArgs } from 'vs/platform/environment/node/argv';
6059
import { RunOnceScheduler } from 'vs/base/common/async';
6160
import { registerContextMenuListener } from 'vs/base/parts/contextmenu/electron-main/contextmenu';
6261
import { homedir } from 'os';
@@ -616,9 +615,9 @@ export class CodeApplication extends Disposable {
616615
// Open our first window
617616
const macOpenFiles: string[] = (<any>global).macOpenFiles;
618617
const context = !!process.env['VSCODE_CLI'] ? OpenContext.CLI : OpenContext.DESKTOP;
619-
const hasCliArgs = hasArgs(args._);
620-
const hasFolderURIs = hasArgs(args['folder-uri']);
621-
const hasFileURIs = hasArgs(args['file-uri']);
618+
const hasCliArgs = args._.length;
619+
const hasFolderURIs = !!args['folder-uri'];
620+
const hasFileURIs = !!args['file-uri'];
622621
const noRecentEntry = args['skip-add-to-recently-opened'] === true;
623622
const waitMarkerFileURI = args.wait && args.waitMarkerFilePath ? URI.file(args.waitMarkerFilePath) : undefined;
624623

src/vs/code/electron-main/windows.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { IBackupMainService, IEmptyWindowBackupInfo } from 'vs/platform/backup/c
1212
import { IEnvironmentService, ParsedArgs } from 'vs/platform/environment/common/environment';
1313
import { IStateService } from 'vs/platform/state/common/state';
1414
import { CodeWindow, defaultWindowState } from 'vs/code/electron-main/window';
15-
import { hasArgs, asArray } from 'vs/platform/environment/node/argv';
1615
import { ipcMain as ipc, screen, BrowserWindow, dialog, systemPreferences, FileFilter } from 'electron';
1716
import { parseLineAndColumnAware } from 'vs/code/node/paths';
1817
import { ILifecycleService, UnloadReason, LifecycleService, LifecycleMainPhase } from 'vs/platform/lifecycle/electron-main/lifecycleMain';
@@ -450,7 +449,7 @@ export class WindowsManager extends Disposable implements IWindowsMainService {
450449
// Make sure to pass focus to the most relevant of the windows if we open multiple
451450
if (usedWindows.length > 1) {
452451

453-
const focusLastActive = this.windowsState.lastActiveWindow && !openConfig.forceEmpty && !hasArgs(openConfig.cli._) && !hasArgs(openConfig.cli['file-uri']) && !hasArgs(openConfig.cli['folder-uri']) && !(openConfig.urisToOpen && openConfig.urisToOpen.length);
452+
const focusLastActive = this.windowsState.lastActiveWindow && !openConfig.forceEmpty && openConfig.cli._.length && !openConfig.cli['file-uri'] && !openConfig.cli['folder-uri'] && !(openConfig.urisToOpen && openConfig.urisToOpen.length);
454453
let focusLastOpened = true;
455454
let focusLastWindow = true;
456455

@@ -811,7 +810,7 @@ export class WindowsManager extends Disposable implements IWindowsMainService {
811810
}
812811

813812
// Extract paths: from CLI
814-
else if (hasArgs(openConfig.cli._) || hasArgs(openConfig.cli['folder-uri']) || hasArgs(openConfig.cli['file-uri'])) {
813+
else if (openConfig.cli._.length || openConfig.cli['folder-uri'] || openConfig.cli['file-uri']) {
815814
windowsToOpen = this.doExtractPathsFromCLI(openConfig.cli);
816815
isCommandLineOrAPICall = true;
817816
}
@@ -885,31 +884,36 @@ export class WindowsManager extends Disposable implements IWindowsMainService {
885884
const parseOptions: IPathParseOptions = { ignoreFileNotFound: true, gotoLineMode: cli.goto, remoteAuthority: cli.remote || undefined };
886885

887886
// folder uris
888-
const folderUris = asArray(cli['folder-uri']);
889-
for (let f of folderUris) {
890-
const folderUri = this.argToUri(f);
891-
if (folderUri) {
892-
const path = this.parseUri({ folderUri }, parseOptions);
893-
if (path) {
894-
pathsToOpen.push(path);
887+
const folderUris = cli['folder-uri'];
888+
if (folderUris) {
889+
for (let f of folderUris) {
890+
const folderUri = this.argToUri(f);
891+
if (folderUri) {
892+
const path = this.parseUri({ folderUri }, parseOptions);
893+
if (path) {
894+
pathsToOpen.push(path);
895+
}
895896
}
896897
}
897898
}
898899

900+
899901
// file uris
900-
const fileUris = asArray(cli['file-uri']);
901-
for (let f of fileUris) {
902-
const fileUri = this.argToUri(f);
903-
if (fileUri) {
904-
const path = this.parseUri(hasWorkspaceFileExtension(f) ? { workspaceUri: fileUri } : { fileUri }, parseOptions);
905-
if (path) {
906-
pathsToOpen.push(path);
902+
const fileUris = cli['file-uri'];
903+
if (fileUris) {
904+
for (let f of fileUris) {
905+
const fileUri = this.argToUri(f);
906+
if (fileUri) {
907+
const path = this.parseUri(hasWorkspaceFileExtension(f) ? { workspaceUri: fileUri } : { fileUri }, parseOptions);
908+
if (path) {
909+
pathsToOpen.push(path);
910+
}
907911
}
908912
}
909913
}
910914

911915
// folder or file paths
912-
const cliArgs = asArray(cli._);
916+
const cliArgs = cli._;
913917
for (let cliArg of cliArgs) {
914918
const path = this.parsePath(cliArg, parseOptions);
915919
if (path) {
@@ -1178,8 +1182,8 @@ export class WindowsManager extends Disposable implements IWindowsMainService {
11781182

11791183
return;
11801184
}
1181-
let folderUris = asArray(openConfig.cli['folder-uri']);
1182-
let fileUris = asArray(openConfig.cli['file-uri']);
1185+
let folderUris = openConfig.cli['folder-uri'] || [];
1186+
let fileUris = openConfig.cli['file-uri'] || [];
11831187
let cliArgs = openConfig.cli._;
11841188

11851189
// Fill in previously opened workspace unless an explicit path is provided and we are not unit testing

src/vs/platform/environment/common/environment.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { URI } from 'vs/base/common/uri';
88

99
export interface ParsedArgs {
1010
_: string[];
11-
'folder-uri'?: string | string[];
12-
'file-uri'?: string | string[];
11+
'folder-uri'?: string[];
12+
'file-uri'?: string[];
1313
_urls?: string[];
1414
help?: boolean;
1515
version?: boolean;
@@ -36,7 +36,7 @@ export interface ParsedArgs {
3636
logExtensionHostCommunication?: boolean;
3737
'extensions-dir'?: string;
3838
'builtin-extensions-dir'?: string;
39-
extensionDevelopmentPath?: string | string[]; // one or more local paths or URIs
39+
extensionDevelopmentPath?: string[]; // one or more local paths or URIs
4040
extensionTestsPath?: string; // either a local path or a URI
4141
'extension-development-confirm-save'?: boolean;
4242
'inspect-extensions'?: string;
@@ -45,14 +45,14 @@ export interface ParsedArgs {
4545
'inspect-search'?: string;
4646
'inspect-brk-search'?: string;
4747
'disable-extensions'?: boolean;
48-
'disable-extension'?: string | string[];
48+
'disable-extension'?: string[];
4949
'list-extensions'?: boolean;
5050
'show-versions'?: boolean;
5151
'category'?: string;
52-
'install-extension'?: string | string[];
53-
'uninstall-extension'?: string | string[];
54-
'locate-extension'?: string | string[];
55-
'enable-proposed-api'?: string | string[];
52+
'install-extension'?: string[];
53+
'uninstall-extension'?: string[];
54+
'locate-extension'?: string[];
55+
'enable-proposed-api'?: string[];
5656
'open-url'?: boolean;
5757
'skip-getting-started'?: boolean;
5858
'skip-release-notes'?: boolean;

src/vs/platform/environment/node/argv.ts

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const helpCategories = {
2222

2323
export interface Option {
2424
id: keyof ParsedArgs;
25-
type: 'boolean' | 'string';
25+
type: 'boolean' | 'string' | 'string[]';
2626
alias?: string;
2727
deprecates?: string; // old deprecated id
2828
args?: string | string[];
@@ -42,32 +42,32 @@ export const options: Option[] = [
4242
{ id: 'version', type: 'boolean', cat: 'o', alias: 'v', description: localize('version', "Print version.") },
4343
{ id: 'help', type: 'boolean', cat: 'o', alias: 'h', description: localize('help', "Print usage.") },
4444
{ id: 'telemetry', type: 'boolean', cat: 'o', description: localize('telemetry', "Shows all telemetry events which VS code collects.") },
45-
{ id: 'folder-uri', type: 'string', cat: 'o', args: 'uri', description: localize('folderUri', "Opens a window with given folder uri(s)") },
46-
{ id: 'file-uri', type: 'string', cat: 'o', args: 'uri', description: localize('fileUri', "Opens a window with given file uri(s)") },
45+
{ id: 'folder-uri', type: 'string[]', cat: 'o', args: 'uri', description: localize('folderUri', "Opens a window with given folder uri(s)") },
46+
{ id: 'file-uri', type: 'string[]', cat: 'o', args: 'uri', description: localize('fileUri', "Opens a window with given file uri(s)") },
4747

4848
{ id: 'extensions-dir', type: 'string', deprecates: 'extensionHomePath', cat: 'e', args: 'dir', description: localize('extensionHomePath', "Set the root path for extensions.") },
4949
{ id: 'list-extensions', type: 'boolean', cat: 'e', description: localize('listExtensions', "List the installed extensions.") },
5050
{ id: 'show-versions', type: 'boolean', cat: 'e', description: localize('showVersions', "Show versions of installed extensions, when using --list-extension.") },
5151
{ id: 'category', type: 'string', cat: 'e', description: localize('category', "Filters installed extensions by provided category, when using --list-extension.") },
52-
{ id: 'install-extension', type: 'string', cat: 'e', args: 'extension-id | path-to-vsix', description: localize('installExtension', "Installs or updates the extension. Use `--force` argument to avoid prompts.") },
53-
{ id: 'uninstall-extension', type: 'string', cat: 'e', args: 'extension-id', description: localize('uninstallExtension', "Uninstalls an extension.") },
54-
{ id: 'enable-proposed-api', type: 'string', cat: 'e', args: 'extension-id', description: localize('experimentalApis', "Enables proposed API features for extensions. Can receive one or more extension IDs to enable individually.") },
52+
{ id: 'install-extension', type: 'string[]', cat: 'e', args: 'extension-id | path-to-vsix', description: localize('installExtension', "Installs or updates the extension. Use `--force` argument to avoid prompts.") },
53+
{ id: 'uninstall-extension', type: 'string[]', cat: 'e', args: 'extension-id', description: localize('uninstallExtension', "Uninstalls an extension.") },
54+
{ id: 'enable-proposed-api', type: 'string[]', cat: 'e', args: 'extension-id', description: localize('experimentalApis', "Enables proposed API features for extensions. Can receive one or more extension IDs to enable individually.") },
5555

5656
{ id: 'verbose', type: 'boolean', cat: 't', description: localize('verbose', "Print verbose output (implies --wait).") },
5757
{ id: 'log', type: 'string', cat: 't', args: 'level', description: localize('log', "Log level to use. Default is 'info'. Allowed values are 'critical', 'error', 'warn', 'info', 'debug', 'trace', 'off'.") },
5858
{ id: 'status', type: 'boolean', alias: 's', cat: 't', description: localize('status', "Print process usage and diagnostics information.") },
5959
{ id: 'prof-startup', type: 'boolean', cat: 't', description: localize('prof-startup', "Run CPU profiler during startup") },
6060
{ id: 'disable-extensions', type: 'boolean', deprecates: 'disableExtensions', cat: 't', description: localize('disableExtensions', "Disable all installed extensions.") },
61-
{ id: 'disable-extension', type: 'string', cat: 't', args: 'extension-id', description: localize('disableExtension', "Disable an extension.") },
61+
{ id: 'disable-extension', type: 'string[]', cat: 't', args: 'extension-id', description: localize('disableExtension', "Disable an extension.") },
6262

6363
{ id: 'inspect-extensions', type: 'string', deprecates: 'debugPluginHost', args: 'port', cat: 't', description: localize('inspect-extensions', "Allow debugging and profiling of extensions. Check the developer tools for the connection URI.") },
6464
{ id: 'inspect-brk-extensions', type: 'string', deprecates: 'debugBrkPluginHost', args: 'port', cat: 't', description: localize('inspect-brk-extensions', "Allow debugging and profiling of extensions with the extension host being paused after start. Check the developer tools for the connection URI.") },
6565
{ id: 'disable-gpu', type: 'boolean', cat: 't', description: localize('disableGPU', "Disable GPU hardware acceleration.") },
6666
{ id: 'max-memory', type: 'string', cat: 't', description: localize('maxMemory', "Max memory size for a window (in Mbytes).") },
6767

6868
{ id: 'remote', type: 'string' },
69-
{ id: 'locate-extension', type: 'string' },
70-
{ id: 'extensionDevelopmentPath', type: 'string' },
69+
{ id: 'locate-extension', type: 'string[]' },
70+
{ id: 'extensionDevelopmentPath', type: 'string[]' },
7171
{ id: 'extensionTestsPath', type: 'string' },
7272
{ id: 'extension-development-confirm-save', type: 'boolean' },
7373
{ id: 'debugId', type: 'string' },
@@ -110,7 +110,7 @@ export function parseArgs(args: string[], isOptionSupported = (_: Option) => tru
110110
}
111111
}
112112

113-
if (o.type === 'string') {
113+
if (o.type === 'string' || o.type === 'string[]') {
114114
string.push(o.id);
115115
if (o.deprecates) {
116116
string.push(o.deprecates);
@@ -132,6 +132,12 @@ export function parseArgs(args: string[], isOptionSupported = (_: Option) => tru
132132
parsedArgs[o.id] = parsedArgs[o.deprecates];
133133
delete parsedArgs[o.deprecates];
134134
}
135+
if (o.type === 'string[]') {
136+
const val = parsedArgs[o.id];
137+
if (val && !Array.isArray(val)) {
138+
parsedArgs[o.id] = [val];
139+
}
140+
}
135141
}
136142

137143
// https://github.com/microsoft/vscode/issues/58177
@@ -224,32 +230,6 @@ export function buildVersionMessage(version: string | undefined, commit: string
224230
return `${version || localize('unknownVersion', "Unknown version")}\n${commit || localize('unknownCommit', "Unknown commit")}\n${process.arch}`;
225231
}
226232

227-
/**
228-
* Converts an argument into an array
229-
* @param arg a argument value. Can be undefined, an entry or an array
230-
*/
231-
export function asArray(arg: string | string[] | undefined): string[] {
232-
if (arg) {
233-
if (Array.isArray(arg)) {
234-
return arg;
235-
}
236-
return [arg];
237-
}
238-
return [];
239-
}
240-
241-
/**
242-
* Returns whether an argument is present.
243-
*/
244-
export function hasArgs(arg: string | string[] | undefined): boolean {
245-
if (arg) {
246-
if (Array.isArray(arg)) {
247-
return !!arg.length;
248-
}
249-
return true;
250-
}
251-
return false;
252-
}
253233

254234
export function addArg(argv: string[], ...args: string[]): string[] {
255235
const endOfArgsMarkerIndex = argv.indexOf('--');

src/vs/platform/launch/electron-main/launchService.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
1717
import { URI } from 'vs/base/common/uri';
1818
import { BrowserWindow, ipcMain, Event as IpcEvent, app } from 'electron';
1919
import { Event } from 'vs/base/common/event';
20-
import { hasArgs } from 'vs/platform/environment/node/argv';
2120
import { coalesce } from 'vs/base/common/arrays';
2221
import { IDiagnosticInfoOptions, IDiagnosticInfo, IRemoteDiagnosticInfo, IRemoteDiagnosticError } from 'vs/platform/diagnostics/common/diagnostics';
2322
import { IMainProcessInfo, IWindowInfo } from 'vs/platform/launch/common/launchService';
@@ -173,7 +172,7 @@ export class LaunchService implements ILaunchService {
173172
}
174173

175174
// Start without file/folder arguments
176-
else if (!hasArgs(args._) && !hasArgs(args['folder-uri']) && !hasArgs(args['file-uri'])) {
175+
else if (!args._.length && !args['folder-uri'] && !args['file-uri']) {
177176
let openNewWindow = false;
178177

179178
// Force new window

src/vs/workbench/contrib/debug/browser/rawDebugSession.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -583,13 +583,9 @@ export class RawDebugSession {
583583

584584
const v = args[key];
585585
if (v) {
586-
if (Array.isArray(v)) {
587-
v.push(value);
588-
} else {
589-
args[key] = [v, value];
590-
}
586+
v.push(value);
591587
} else {
592-
args[key] = value;
588+
args[key] = [value];
593589
}
594590

595591
} else {

0 commit comments

Comments
 (0)