Skip to content

Commit b8bb5e7

Browse files
committed
Cleanup src/vs/platform/environment/node/argv.ts. Fixes microsoft#76239
1 parent 57c8495 commit b8bb5e7

6 files changed

Lines changed: 50 additions & 39 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { app, dialog } from 'electron';
88
import { assign } from 'vs/base/common/objects';
99
import { isWindows, IProcessEnvironment, isMacintosh } from 'vs/base/common/platform';
1010
import product from 'vs/platform/product/common/product';
11-
import { parseMainProcessArgv } from 'vs/platform/environment/node/argvHelper';
12-
import { addArg, createWaitMarkerFile } from 'vs/platform/environment/node/argv';
11+
import { parseMainProcessArgv, addArg } from 'vs/platform/environment/node/argvHelper';
12+
import { createWaitMarkerFile } from 'vs/platform/environment/node/waitMarkerFile';
1313
import { mkdirp } from 'vs/base/node/pfs';
1414
import { validatePaths } from 'vs/code/node/paths';
1515
import { LifecycleMainService, ILifecycleMainService } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';

src/vs/code/node/cli.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
import * as os from 'os';
77
import * as fs from 'fs';
88
import { spawn, ChildProcess, SpawnOptions } from 'child_process';
9-
import { buildHelpMessage, buildVersionMessage, addArg, createWaitMarkerFile, OPTIONS } from 'vs/platform/environment/node/argv';
10-
import { parseCLIProcessArgv } from 'vs/platform/environment/node/argvHelper';
9+
import { buildHelpMessage, buildVersionMessage, OPTIONS } from 'vs/platform/environment/node/argv';
10+
import { parseCLIProcessArgv, addArg } from 'vs/platform/environment/node/argvHelper';
11+
import { createWaitMarkerFile } from 'vs/platform/environment/node/waitMarkerFile';
1112
import { ParsedArgs } from 'vs/platform/environment/common/environment';
1213
import product from 'vs/platform/product/common/product';
1314
import * as paths from 'vs/base/common/path';

src/vs/code/test/node/argv.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55
import * as assert from 'assert';
6-
import { formatOptions, Option, addArg } from 'vs/platform/environment/node/argv';
6+
import { formatOptions, Option } from 'vs/platform/environment/node/argv';
7+
import { addArg } from 'vs/platform/environment/node/argvHelper';
78

89
suite('formatOptions', () => {
910

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

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@ import * as minimist from 'vscode-minimist';
77
import * as os from 'os';
88
import { localize } from 'vs/nls';
99
import { ParsedArgs } from 'vs/platform/environment/common/environment';
10-
import { join } from 'vs/base/common/path';
11-
import { writeFileSync } from 'vs/base/node/pfs';
1210

1311
/**
1412
* This code is also used by standalone cli's. Avoid adding any other dependencies.
1513
*/
16-
1714
const helpCategories = {
1815
o: localize('optionsUpperCase', "Options"),
1916
e: localize('extensionsManagement', "Extensions Management"),
@@ -161,7 +158,7 @@ export function parseArgs<T>(args: string[], options: OptionDescriptions<T>, err
161158
}
162159
}
163160
}
164-
// remote aliases to avoid confusion
161+
// remove aliases to avoid confusion
165162
const parsedArgs = minimist(args, { string, boolean, alias });
166163

167164
const cleanedArgs: any = {};
@@ -310,33 +307,3 @@ export function buildVersionMessage(version: string | undefined, commit: string
310307
return `${version || localize('unknownVersion', "Unknown version")}\n${commit || localize('unknownCommit', "Unknown commit")}\n${process.arch}`;
311308
}
312309

313-
export function addArg(argv: string[], ...args: string[]): string[] {
314-
const endOfArgsMarkerIndex = argv.indexOf('--');
315-
if (endOfArgsMarkerIndex === -1) {
316-
argv.push(...args);
317-
} else {
318-
// if the we have an argument "--" (end of argument marker)
319-
// we cannot add arguments at the end. rather, we add
320-
// arguments before the "--" marker.
321-
argv.splice(endOfArgsMarkerIndex, 0, ...args);
322-
}
323-
324-
return argv;
325-
}
326-
327-
export function createWaitMarkerFile(verbose?: boolean): string | undefined {
328-
const randomWaitMarkerPath = join(os.tmpdir(), Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 10));
329-
330-
try {
331-
writeFileSync(randomWaitMarkerPath, '');
332-
if (verbose) {
333-
console.log(`Marker file for --wait created: ${randomWaitMarkerPath}`);
334-
}
335-
return randomWaitMarkerPath;
336-
} catch (err) {
337-
if (verbose) {
338-
console.error(`Failed to create marker file for --wait: ${err}`);
339-
}
340-
return undefined;
341-
}
342-
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,17 @@ export function parseCLIProcessArgv(processArgv: string[]): ParsedArgs {
6969

7070
return parseAndValidate(args, true);
7171
}
72+
73+
export function addArg(argv: string[], ...args: string[]): string[] {
74+
const endOfArgsMarkerIndex = argv.indexOf('--');
75+
if (endOfArgsMarkerIndex === -1) {
76+
argv.push(...args);
77+
} else {
78+
// if the we have an argument "--" (end of argument marker)
79+
// we cannot add arguments at the end. rather, we add
80+
// arguments before the "--" marker.
81+
argv.splice(endOfArgsMarkerIndex, 0, ...args);
82+
}
83+
84+
return argv;
85+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
/**
7+
* This code is also used by standalone cli's. Avoid adding dependencies to keep the size of the cli small.
8+
*/
9+
import * as path from 'vs/base/common/path';
10+
import * as os from 'os';
11+
import * as fs from 'fs';
12+
13+
export function createWaitMarkerFile(verbose?: boolean): string | undefined {
14+
const randomWaitMarkerPath = path.join(os.tmpdir(), Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 10));
15+
16+
try {
17+
fs.writeFileSync(randomWaitMarkerPath, ''); // use built-in fs to avoid dragging in more dependencies
18+
if (verbose) {
19+
console.log(`Marker file for --wait created: ${randomWaitMarkerPath}`);
20+
}
21+
return randomWaitMarkerPath;
22+
} catch (err) {
23+
if (verbose) {
24+
console.error(`Failed to create marker file for --wait: ${err}`);
25+
}
26+
return undefined;
27+
}
28+
}

0 commit comments

Comments
 (0)