mow.cli icon indicating copy to clipboard operation
mow.cli copied to clipboard

Support environment variable as a *Opt parameter

Open nmaupu opened this issue 8 years ago • 4 comments

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.

nmaupu avatar Nov 05 '17 16:11 nmaupu

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.

jawher avatar Nov 05 '17 16:11 jawher

Indeed, goog point. The only solution would be to create new dedicated funcs for that.

nmaupu avatar Nov 05 '17 17:11 nmaupu

I came here asking for env var support having not sufficiently RTFM'd, this is great!

silasdavis avatar May 04 '18 13:05 silasdavis

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.

pkazmier avatar May 05 '18 02:05 pkazmier