kong icon indicating copy to clipboard operation
kong copied to clipboard

Using `env` with `cmd` does not appear to work as expected.

Open nullism opened this issue 1 year ago • 3 comments

Hello all!

Playground demonstrating the issue: https://go.dev/play/p/LFPIRwbTCqc

If we had a struct like:

var CLI struct {
    One CmdOne `cmd:"" env:"CMD"`
    Two CmdTwo `cmd:"" env:"CMD"`
}

Then env CMD=one cli still fails with expected one of "one", "two" which doesn't seem correct to me. Perhaps I'm missing something in the usage?

However, cli one or cli two works as expected.

Thanks for your time!

PS:

I know we can do something like this, but it seems to defeat the purpose of env:"X":

	if cmd := os.Getenv("CMD"); cmd != "" {
		os.Args = append([]string{os.Args[0], cmd}, os.Args[1:]...)
	}

nullism avatar Mar 01 '24 18:03 nullism

If using env with cmd is not intended to be supported, could we get Kong to produce an error when both are specified?

nullism avatar Mar 01 '24 18:03 nullism

env is not supported, correct. Kong currently doesn't error for any use of unsupported tags. I think doing that robustly would require some thought.

alecthomas avatar Mar 01 '24 20:03 alecthomas

Ah, I haven't dug into the code, but sounds like it's more involved than just checking if cmd and env then error.

Thanks very much for the reply. Love the package!

nullism avatar Mar 01 '24 20:03 nullism