Skip to content

Commit

Permalink
Convert all src process.env access to util.envGetValue
Browse files Browse the repository at this point in the history
  • Loading branch information
lygstate committed Apr 15, 2021
1 parent 8bcd0c8 commit 21aada3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
16 changes: 8 additions & 8 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ class ExtensionManager implements vscode.Disposable {
await scanForKitsIfNeeded(cmt);

let should_configure = cmt.workspaceContext.config.configureOnOpen;
if (should_configure === null && process.env['CMT_TESTING'] !== '1') {
if (should_configure === null && util.envGetValue(process.env, 'CMT_TESTING') !== '1') {
interface Choice1 {
title: string;
doConfigure: boolean;
Expand Down Expand Up @@ -858,7 +858,7 @@ class ExtensionManager implements vscode.Disposable {
* Show UI to allow the user to select an active kit
*/
async selectKit(folder?: vscode.WorkspaceFolder): Promise<boolean> {
if (process.env['CMT_TESTING'] === '1') {
if (util.envGetValue(process.env, 'CMT_TESTING') === '1') {
log.trace(localize('selecting.kit.in.test.mode', 'Running CMakeTools in test mode. selectKit is disabled.'));
return false;
}
Expand Down Expand Up @@ -1326,7 +1326,7 @@ class ExtensionManager implements vscode.Disposable {
* Show UI to allow the user to add an active configure preset
*/
async addConfigurePreset(folder: vscode.WorkspaceFolder): Promise<boolean> {
if (process.env['CMT_TESTING'] === '1') {
if (util.envGetValue(process.env, 'CMT_TESTING') === '1') {
log.trace(localize('add.config.preset.in.test.mode', 'Running CMakeTools in test mode. addConfigurePreset is disabled.'));
return false;
}
Expand All @@ -1343,7 +1343,7 @@ class ExtensionManager implements vscode.Disposable {
* Show UI to allow the user to add an active build preset
*/
async addBuildPreset(folder: vscode.WorkspaceFolder): Promise<boolean> {
if (process.env['CMT_TESTING'] === '1') {
if (util.envGetValue(process.env, 'CMT_TESTING') === '1') {
log.trace(localize('add.build.preset.in.test.mode', 'Running CMakeTools in test mode. addBuildPreset is disabled.'));
return false;
}
Expand All @@ -1360,7 +1360,7 @@ class ExtensionManager implements vscode.Disposable {
* Show UI to allow the user to add an active test preset
*/
async addTestPreset(folder: vscode.WorkspaceFolder): Promise<boolean> {
if (process.env['CMT_TESTING'] === '1') {
if (util.envGetValue(process.env, 'CMT_TESTING') === '1') {
log.trace(localize('add.test.preset.in.test.mode', 'Running CMakeTools in test mode. addTestPreset is disabled.'));
return false;
}
Expand All @@ -1378,7 +1378,7 @@ class ExtensionManager implements vscode.Disposable {
* Show UI to allow the user to select an active configure preset
*/
async selectConfigurePreset(folder?: vscode.WorkspaceFolder): Promise<boolean> {
if (process.env['CMT_TESTING'] === '1') {
if (util.envGetValue(process.env, 'CMT_TESTING') === '1') {
log.trace(localize('selecting.config.preset.in.test.mode', 'Running CMakeTools in test mode. selectConfigurePreset is disabled.'));
return false;
}
Expand Down Expand Up @@ -1406,7 +1406,7 @@ class ExtensionManager implements vscode.Disposable {
* Show UI to allow the user to select an active build preset
*/
async selectBuildPreset(folder?: vscode.WorkspaceFolder): Promise<boolean> {
if (process.env['CMT_TESTING'] === '1') {
if (util.envGetValue(process.env, 'CMT_TESTING') === '1') {
log.trace(localize('selecting.build.preset.in.test.mode', 'Running CMakeTools in test mode. selectBuildPreset is disabled.'));
return false;
}
Expand All @@ -1428,7 +1428,7 @@ class ExtensionManager implements vscode.Disposable {
* Show UI to allow the user to select an active test preset
*/
async selectTestPreset(folder?: vscode.WorkspaceFolder): Promise<boolean> {
if (process.env['CMT_TESTING'] === '1') {
if (util.envGetValue(process.env, 'CMT_TESTING') === '1') {
log.trace(localize('selecting.test.preset.in.test.mode', 'Running CMakeTools in test mode. selectTestPreset is disabled.'));
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/installs/visual-studio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as path from 'path';

import * as logging from '../logging';
import * as proc from '../proc';
import {thisExtensionPath} from '../util';
import {envGetValue, thisExtensionPath} from '../util';
import * as nls from 'vscode-nls';


Expand Down Expand Up @@ -61,7 +61,7 @@ export async function vsInstallations(): Promise<VSInstallation[]> {
const installs = [] as VSInstallation[];
const inst_ids = [] as string[];
const vswhere_exe = path.join(thisExtensionPath(), 'res', 'vswhere.exe');
const sys32_path = path.join(process.env.WINDIR as string, 'System32');
const sys32_path = path.join(envGetValue(process.env, 'WINDIR') ?? 'C:\\Windows', 'System32');

const vswhere_args =
['/c', `${sys32_path}\\chcp 65001>nul && "${vswhere_exe}" -all -format json -utf8 -products * -legacy -prerelease`];
Expand Down
2 changes: 1 addition & 1 deletion src/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class SingletonLogger {
case LogLevel.Debug:
case LogLevel.Info:
case LogLevel.Note:
if (process.env['CMT_QUIET_CONSOLE'] !== '1') {
if (util.envGetValue(process.env, 'CMT_QUIET_CONSOLE') !== '1') {
// tslint:disable-next-line
console.info('[CMakeTools]', raw_message);
}
Expand Down
30 changes: 15 additions & 15 deletions src/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ interface VSCMakePaths {

class WindowsEnvironment {
get AppData(): string | undefined {
return process.env['APPDATA'];
return util.envGetValue(process.env, 'APPDATA');
}

get LocalAppData(): string | undefined {
return process.env['LOCALAPPDATA'];
return util.envGetValue(process.env, 'LOCALAPPDATA');
}

get AllUserProfile(): string | undefined {
return process.env['ProgramData'];
return util.envGetValue(process.env, 'ProgramData');
}

get ComSpec(): string {
let comSpec = process.env['ComSpec'];
let comSpec = util.envGetValue(process.env, 'ComSpec');

if (undefined === comSpec) {
comSpec = this.SystemRoot! + '\\system32\\cmd.exe';
Expand All @@ -40,31 +40,31 @@ class WindowsEnvironment {
}

get HomeDrive(): string | undefined {
return process.env['HOMEDRIVE'];
return util.envGetValue(process.env, 'HOMEDRIVE');
}

get HomePath(): string | undefined {
return process.env['HOMEPATH'];
return util.envGetValue(process.env, 'HOMEPATH');
}

get ProgramFilesX86(): string | undefined {
return process.env['ProgramFiles(x86)'];
return util.envGetValue(process.env, 'ProgramFiles(x86)');
}

get ProgramFiles(): string | undefined {
return process.env['ProgramFiles'];
return util.envGetValue(process.env, 'ProgramFiles');
}

get SystemDrive(): string | undefined {
return process.env['SystemDrive'];
return util.envGetValue(process.env, 'SystemDrive');
}

get SystemRoot(): string | undefined {
return process.env['SystemRoot'];
return util.envGetValue(process.env, 'SystemRoot');
}

get Temp(): string | undefined {
return process.env['TEMP'];
return util.envGetValue(process.env, 'TEMP');
}
}

Expand All @@ -81,9 +81,9 @@ class Paths {
*/
get userHome(): string {
if (process.platform === 'win32') {
return path.join(process.env['HOMEDRIVE'] || 'C:', process.env['HOMEPATH'] || 'Users\\Public');
return path.join(util.envGetValue(process.env, 'HOMEDRIVE') ?? 'C:', util.envGetValue(process.env, 'HOMEPATH') ?? 'Users\\Public');
} else {
return process.env['HOME'] || process.env['PROFILE']!;
return util.envGetValue(process.env, 'HOME') ?? util.envGetValue(process.env, 'PROFILE') ?? '/root';
}
}

Expand All @@ -95,7 +95,7 @@ class Paths {
if (process.platform == 'win32') {
return this.windows.LocalAppData!;
} else {
const xdg_dir = process.env['XDG_DATA_HOME'];
const xdg_dir = util.envGetValue(process.env, 'XDG_DATA_HOME');
if (xdg_dir) {
return xdg_dir;
}
Expand All @@ -108,7 +108,7 @@ class Paths {
if (process.platform == 'win32') {
return this.windows.AppData!;
} else {
const xdg_dir = process.env['XDG_CONFIG_HOME'];
const xdg_dir = util.envGetValue(process.env, 'XDG_CONFIG_HOME');
if (xdg_dir) {
return xdg_dir;
}
Expand Down

0 comments on commit 21aada3

Please sign in to comment.