Incorporating Environment Variables? #402
-
Hi all- Please forgive the n00b question. I was wondering peoples' thoughts on where/how to incorporate environment variables. Common rules of precedence dictates that cli params usually override environment variables, but when I attempt to add some options into the Constructor Initialization piece: public class CreateTicketSettings : CommandSettings
{
public CreateTicketSettings(string platform)
{
var platformEV = System.Environment.GetEnvironmentVariable("PLATFORM");
if (platform != null)
{
Platform = platform;
}
else Platform = platformEV;
}
[Description("Platform to create request for (web, ios, android)")]
[CommandArgument(0, "<platform>")]
public string Platform { get; set; }
} I can only ever successfully resolve the type (avoiding |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
I was trying to come up with something clever to hack around making this happen without resorting to uglifying the settings, but I'm coming up blank. I think it's a solid use case for adding support to the library. But how to implement is something I'm not sure of. I'd be tempted to go down one of two routes
If you get a chance can you add a new issue with the "Enhancement" tag? I'll move my thoughts over there too. Might be a better place for designing out this feature. |
Beta Was this translation helpful? Give feedback.
-
Since you do not require the In this case, you can add custom validation that assigns the environment variable if
I also have an idea of how to solve this more nicely, and I will create an issue and PR for it later today. |
Beta Was this translation helpful? Give feedback.
-
See also PR in #540 |
Beta Was this translation helpful? Give feedback.
Since you do not require the
Platform
parameter to be passed via the command line, it must be optional.In this case, you can add custom validation that assigns the environment variable if
Platform
is not set or returns a validation error if neither is set.