aboutsummaryrefslogtreecommitdiffstats
path: root/packages/dev-utils/src/env.ts
blob: e74ef3d23e176a9d52bcc3b813a06a87f44405db (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import * as _ from 'lodash';
import * as process from 'process';

export enum EnvVars {
    SolidityCoverage = 'SOLIDITY_COVERAGE',
    SolidityProfiler = 'SOLIDITY_PROFILER',
    VerboseGanache = 'VERBOSE_GANACHE',
}

export const env = {
    parseBoolean(key: string): boolean {
        let isTrue: boolean;
        const envVarValue = process.env[key];
        if (envVarValue === 'true') {
            isTrue = true;
        } else if (envVarValue === 'false' || _.isUndefined(envVarValue)) {
            isTrue = false;
        } else {
            throw new Error(
                `Failed to parse ENV variable ${key} as boolean. Please make sure it's either true or false. Defaults to false`,
            );
        }
        return isTrue;
    },
};