Introducing Flaggy: A new simple solution for flag packages
Looking for something more in a flag package that doesn’t require any external dependencies? How about giving Flaggy a try? We take a look at the features, what sets it apart, and see what features are available to test out.
Flaggy is an “Idiomatic Go input parsing with the subcommands, positional values, and flags at any position. No required project or package layout and no external dependencies”. Let’s take a look at its features and see what sets it apart from other, commonly used flag packages.
Created by technology enthusiast Eric Greer (seen sporting a fashionable Virtual Boy on his blog), Flaggy was created to fulfill the needs that other flag packages didn’t address. Various popular flag packages, such as Cobra, go-flags, and gnuflag, all lacked something or just simply weren’t, well, simple enough. Either creating subcommands was difficult, declarations were wordy and time consuming, or it required external dependencies.
Flaggy is fast and makes sense, naturally. Flags can be at any position, and perhaps most importantly, it has no external dependencies and has no required project or package layout. This sets it apart from other popular flag packages right out of the box.
On his blog, Eric Greer says, “It’s an easy to use flags package that makes the right assumptions without restricting your workflow. You can get very advanced if you want to, but by default flaggy does an excellent job of doing everything it possibly can for you without asking.” Sounds great, what else can it do?
SEE ALSO: Top 5 IDEs for Go
Let’s have a look at some of the interesting key features listed on GitHub and see what this new creation can do and just how simple and freedom-granting it really is:
- Flaggy supports 35 different flag types
- Any flag can be at any position
- Nested subcommands
- Set a name and description for your program
- Positional subcommands and parameters
- Global and subcommand positional parameters
- Customizable help templates
- Readable help output
- Unlimited trailing arguments after a
- Flags can use a single dash or double dash (
Simplicity lends itself to Flaggy’s sleek build. One small program only needs one flag. Makes sense, doesn’t it? The bonus of its simplicity is that Flaggy is fast. Parsing is practically lightning speed.
Subcommands are also easy to use and versatile. They can each have their own unique flag. Subcommands can be even be nested on each other – subcommand to subcommand.
The list of supported flag types is long and varied, but includes string, bool, time.Duration, float64 and float 32, and others. Give it a look on GitHub.
See for yourself: Examples
Here’s a simple example:
./yourApp -f test
// Declare variables and their defaults var stringFlag = "defaultValue" // Add a flag flaggy.String(&stringFlag, "f", "flag", "A test string flag") // Parse the flag flaggy.Parse() // Use the flag print(stringFlag)
Want to give it a try? Greer states that it has been tested extensively, so it is ready to use without any tinkering. Give it a test and maybe you’ll be kicking your old favorite flag package to the curb and replacing it with this one. Since this project is so new, we will be keeping our eyes open to see if there any new updates or features that will come. For now though, have fun checking it out!
Check out Eric Greer’s other GitHub repos, including a Go package for working with headless Chrome.