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

Unknown number of positional arguments #79

Closed
uuuvn opened this issue May 10, 2022 · 6 comments · Fixed by #80
Closed

Unknown number of positional arguments #79

uuuvn opened this issue May 10, 2022 · 6 comments · Fixed by #80
Labels
bug Something isn't working

Comments

@uuuvn
Copy link

uuuvn commented May 10, 2022

A simple example:
mycoolpackagemanager install pkg1 pkg2 pkg3 ... pkgN
Is this supported? I didn't find anything about this

@integrii
Copy link
Owner

Yep. It is supported to get TrailingArguments, as well as Positional Arguments...

In your example, install would be a Subcommand. pkg1, pkg2, pkg3 would be TrailingArguments.

You can get TrailingArguments with flaggy.TrailingArguments[0].

@uuuvn
Copy link
Author

uuuvn commented May 17, 2022

So, i need to do something like: mycoolpackagemanager install -- coolpackage1 coolpackage2 coolpackageN ?
Is it possible without '--'?

@uuuvn
Copy link
Author

uuuvn commented May 17, 2022

I had no problems with getopt-long in C, and I was surprised to notice that with all sorts of unnecessary bloat libraries, there is no "perfect" argument parser in go.
Flaggy is the closest to the ideal, but things like this (and dynamically linked 2.5 megabyte binary) scare me away from go

@integrii
Copy link
Owner

The binary for go is bigger, but the go runtime contains a ton of good stuff for concurrency, garbage collection, and thread handling...

I actually just tested this because I wasn't 100% sure anymore, and noticed bad behavior wherein trailing arguments were not set as I would have expected them to be... Checking it out when I get a moment.

@integrii
Copy link
Owner

Fixed in tag v1.5.2!

go get -u github.com/integrii/flaggy

@uuuvn
Copy link
Author

uuuvn commented Jun 3, 2022

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants