Skip to content

Commit da0e7cb

Browse files
committed
Improve variable names
1 parent 2d9f717 commit da0e7cb

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/config.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -540,20 +540,24 @@ export function findHomeDir(): string | null {
540540
}
541541
return null;
542542
}
543+
// $HOME is always favored, but the k8s go-client prefers the other two env vars
544+
// differently depending on whether .kube/config exists or not.
543545
const homeDrivePath = process.env.HOMEDRIVE && process.env.HOMEPATH ?
544546
path.join(process.env.HOMEDRIVE, process.env.HOMEPATH) : null;
545-
const dirList1: string[] = dropDuplicatesAndNils([process.env.HOME, homeDrivePath, process.env.USERPROFILE]);
546-
const dirList2: string[] = dropDuplicatesAndNils([process.env.HOME, process.env.USERPROFILE, homeDrivePath]);
547+
const favourHomeDrivePathList: string[] =
548+
dropDuplicatesAndNils([process.env.HOME, homeDrivePath, process.env.USERPROFILE]);
549+
const favourUserProfileList: string[] =
550+
dropDuplicatesAndNils([process.env.HOME, process.env.USERPROFILE, homeDrivePath]);
547551
// 1. the first of %HOME%, %HOMEDRIVE%%HOMEPATH%, %USERPROFILE% containing a `.kube\config` file is returned.
548-
for (const dir of dirList1) {
552+
for (const dir of favourHomeDrivePathList) {
549553
try {
550554
fs.accessSync(path.join(dir, '.kube', 'config'));
551555
return dir;
552556
// tslint:disable-next-line:no-empty
553557
} catch (ignore) {}
554558
}
555559
// 2. ...the first of %HOME%, %USERPROFILE%, %HOMEDRIVE%%HOMEPATH% that exists and is writeable is returned
556-
for (const dir of dirList2) {
560+
for (const dir of favourUserProfileList) {
557561
try {
558562
const lstat = fs.lstatSync(dir);
559563
// tslint:disable-next-line:no-bitwise
@@ -564,7 +568,7 @@ export function findHomeDir(): string | null {
564568
} catch (ignore) {}
565569
}
566570
// 3. ...the first of %HOME%, %USERPROFILE%, %HOMEDRIVE%%HOMEPATH% that exists is returned.
567-
for (const dir of dirList2) {
571+
for (const dir of favourUserProfileList) {
568572
try {
569573
fs.accessSync(dir);
570574
return dir;
@@ -573,7 +577,7 @@ export function findHomeDir(): string | null {
573577
}
574578
// 4. if none of those locations exists, the first of
575579
// %HOME%, %USERPROFILE%, %HOMEDRIVE%%HOMEPATH% that is set is returned.
576-
return dirList2[0] || null;
580+
return favourUserProfileList[0] || null;
577581
}
578582

579583
export interface Named {

0 commit comments

Comments
 (0)