Support environment variable as a *Opt parameter
For a more concise declaration, it would be very nice to be able to make a call such as :
recursive := cp.BoolOpt("R recursive", false, "recursively copy the src to dst", "VAR_RECURSIVE")
Instead of :
recursive = cp.Bool(cli.BoolOpt{
Name: "R recursive",
Value: false,
Desc: "copy src files recursively",
EnvVar: "VAR_RECURSIVE"
})
SetByUser would not be set to anything.
I can make a PR if you want me to.
Unfortunately this is not possible without breaking backwards compatibility: Go does not support method/function overloading, so this would require changing the signature of the *Opt methods, thus breaking all of this library users.
Indeed, goog point. The only solution would be to create new dedicated funcs for that.
I came here asking for env var support having not sufficiently RTFM'd, this is great!
I’d propose a new set of functions using functional options as described here:
https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis
This would have solved the issue that is preventing the existing API from being extended.