Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
purpleidea opened this issue Mar 1, 2024 · 2 comments
Open

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

purpleidea opened this issue Mar 1, 2024 · 2 comments
Labels
v2-planned Planned for v2

Comments

@purpleidea
Copy link
Contributor

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!

@alexflint
Copy link
Owner

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 alexflint added the v2-planned Planned for v2 label Mar 2, 2024
@purpleidea
Copy link
Contributor Author

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v2-planned Planned for v2
Projects
None yet
Development

No branches or pull requests

2 participants