integrii / flaggy

Idiomatic Go input parsing with subcommands, positional values, and flags at any position. No required project or package layout and no external dependencies.
The Unlicense
856 stars 30 forks source link

Unknown number of positional arguments #79

Closed uuuvn closed 2 years ago

uuuvn commented 2 years ago

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

integrii commented 2 years ago

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 commented 2 years ago

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

uuuvn commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

Fixed in tag v1.5.2!

go get -u github.com/integrii/flaggy

uuuvn commented 2 years ago

Thanks!