-
Notifications
You must be signed in to change notification settings - Fork 13
Environment variables
Adam Bajguz edited this page Aug 18, 2020
·
7 revisions
An option can be configured to use the value of an environment variable as a fallback. If an option was not specified by the user, the value will be extracted from that environment variable instead. This also works on options which are marked as required.
[Command]
public class AuthCommand : ICommand
{
[CommandOption("token", IsRequired = true, EnvironmentVariableName = "AUTH_TOKEN")]
public string AuthToken { get; set; }
public ValueTask ExecuteAsync(IConsole console)
{
console.Output.WriteLine(AuthToken);
return default;
}
}
> $env:AUTH_TOKEN="test"
> myapp.exe
test
Environment variables can be used as fallback for options of enumerable types too. In this case, the value of the variable will be split by Path.PathSeparator
(which is ;
on Windows, :
on Linux).
Getting started
Advanced features
- Reporting errors
- Exception handling
- Metadata and startup message
- Graceful cancellation
- Dependency injection
- Middleware pipeline
- Environment variables
Utilities
Tests
Misc