Open
Description
Can I specify an environment variable to use as a source for an option's value if the option was not specified on the command line?
The simplest way I have found so far is:
new Option<string?>("--some-option", () => Environment.GetEnvironmentVariable("SOME_OPTION"), "description...")
However, this runs into a couple of hurdles:
- The environment variable is expanded and shown in the help. This might be an issue if the environment variable is being used on sensitive options like
--password
, as typing in a command incorrectly could print the option to standard out. - The name of the environment variable isn't printed in the help unless it is manually added to the description.
It would be nice if I could do something like:
new Option<string>("--some-option", () => "default-value", "description...") {
EnvironmentVariable = "SOME_OPTION", //Perhaps this could be an array instead?
};
The help builder could then present the environment variable information in a consistent & nice way like it does for defaults.
The issue with this is that it seems like the parser reading environment variables might be undesirable. An alternative may be to increase customization around defaults to let us print out default info differently with the existing help?