PeanutButter
Loading...
Searching...
No Matches
PeanutButter.Utils.Env Class Reference

Provides easy access to environment variables with fallback. More...

Static Public Member Functions

static string String (string envVar, string fallback)
 Returns the value of the named environment variable or the fallback if that variable is not set.
 
static int Integer (string envVar, int fallback, int? min=null, int? max=null)
 Tries to return an integer value set as an environment variable.
 
static decimal Decimal (string envVar, decimal fallback, decimal? min=null, decimal? max=null)
 Tries to return a decimal value set as an environment variable.
 
static bool Flag (string envVar, bool fallback)
 Tries to return a boolean value set as an environment variable.
 

Detailed Description

Provides easy access to environment variables with fallback.

Member Function Documentation

◆ Decimal()

static decimal PeanutButter.Utils.Env.Decimal ( string  envVar,
decimal  fallback,
decimal?  min = null,
decimal?  max = null 
)
static

Tries to return a decimal value set as an environment variable.

  • if the variable is not set, returns the fallback
  • if the variable value is not a decimal, throws
  • before returning, validate it's within any specified range and, if not, will clip to be within that range
Parameters
envVar
fallback
min
max
Returns

◆ Flag()

static bool PeanutButter.Utils.Env.Flag ( string  envVar,
bool  fallback 
)
static

Tries to return a boolean value set as an environment variable.

  • if the variable is not set, returns the fallback
  • if the variable value is not a recognised boolean, throws
    • truthy values: true, 1, yes, on
    • falsy values: false, 0, no, off parsing is case-insensitive
Parameters
envVar
fallback
Returns

◆ Integer()

static int PeanutButter.Utils.Env.Integer ( string  envVar,
int  fallback,
int?  min = null,
int?  max = null 
)
static

Tries to return an integer value set as an environment variable.

  • if the variable is not set, returns the fallback
  • if the variable is not an integer, throws
  • before returning, validate it's within any specified range and, if not, will clip to be within that range
Parameters
envVar
fallback
min
max
Returns

◆ String()

static string PeanutButter.Utils.Env.String ( string  envVar,
string  fallback 
)
static

Returns the value of the named environment variable or the fallback if that variable is not set.

Parameters
envVar
fallback
Returns

The documentation for this class was generated from the following file: