go-arg icon indicating copy to clipboard operation
go-arg copied to clipboard

The os.Args input shouldn't avoid the argv[0]

Open purpleidea opened this issue 1 year ago • 2 comments

For the v2/ API, I recommend we accept the full os.Args list, rather than taking off the zeroth argument. Most of the API's out there assume you're passing in the zeroth arg, and I don't know why we should be different.

Furthermore, it would be excellent if the library would actually parse out the zeroth arg. For example, in your top-level args struct, you could do:

type Args struct {
	// XXX: We cannot have both subcommands and a positional argument.
	// XXX: I think it's a bug of this library that it can't handle argv[0].
	Argv0 string `arg:"zeroth"` // some special tag could let it know where to put it

or similar, so that we extract this value correctly.

This changes the behaviour, so I recommend it happen for v2.

Thanks!

purpleidea avatar Mar 01 '24 23:03 purpleidea

Good suggestion re assuming that the input args include all of os.Args in v2, but I'm not sure about the arg:"zeroth" tag idea -- I think it would be simpler to let people separately access os.Args[0] if/when they need it.

alexflint avatar Mar 02 '24 13:03 alexflint

Yeah so most importantly is that the Parser should accept all of it, but I think it might be worth considering a mechanism to extract the value too (even though it's trivial) -- this way if you're parsing something, go-arg can be the full API to the CLI and you don't need to separately pass the data out of band. (Remember you might be parsing something.Args instead of os.Args.)

purpleidea avatar Mar 02 '24 14:03 purpleidea