Add support for env in Swift Argument Parser

Something it was not convenient to directly pass a flag or option to the CLI tool. And the called want to add the feature through env value.

And as a tool based on Swift Argument Parser, we would do many ugly stuff to make it support the env value like the following.

if flagA || ProcessInfo.processInfo.environment["FLAG_A"] != nil { ... }

Could we add a new nullable param like "EnvName:String?=nil" or "supportEnv:Bool=false" in the initializer on Option and Flag to support this feature?

If supportEnv is true and EnvName is nil, it can be inferred as the all CAPs form of the flag name

3 Likes
Terms of Service

Privacy Policy

Cookie Policy