Class EnvironmentHelper
Shared utilities for environment variable access. Provides consistent error handling for required environment variables.
public static class EnvironmentHelper
- Inheritance
-
EnvironmentHelper
- Inherited Members
Methods
Get(string)
Gets an environment variable value, or null if not set.
public static string? Get(string name)
Parameters
namestringEnvironment variable name.
Returns
GetOrDefault(string, string)
Gets an environment variable with a default value if not set.
public static string GetOrDefault(string name, string defaultValue)
Parameters
Returns
GetRequired(string, string?)
Gets a required environment variable, throwing if not set.
public static string GetRequired(string name, string? description = null)
Parameters
namestringEnvironment variable name.
descriptionstringOptional description for clearer error messages.
Returns
Exceptions
- InvalidOperationException
Thrown when the variable is not set.
GetRequiredOrPrompt(string, string, bool)
Gets a required environment variable, prompting the user if not set. After prompting, sets the environment variable for the current process so subsequent calls and child processes can use it. In non-interactive mode (CI/server), throws an exception instead of prompting.
public static string GetRequiredOrPrompt(string name, string description, bool isSecret = false)
Parameters
namestringEnvironment variable name.
descriptionstringDescription shown in the prompt.
isSecretboolIf true, hides input (for tokens/passwords).
Returns
- string
The environment variable value.