days
1
3
hours
1
7
minutes
5
4
seconds
5
3
search
Position your flags

Introducing Flaggy: A new simple solution for flag packages

Sarah Schlothauer
flaggy
© Shutterstock / L F File

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.

Enter: Flaggy

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

Key features

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 (--flag-flag-f--f)

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.

SEE ALSO: Kotlin and Java go well together, report shows

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)

More examples are available here on GitHub and on the GoDoc.

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.

Author
Sarah Schlothauer

Sarah Schlothauer

All Posts by Sarah Schlothauer

Sarah Schlothauer is an assistant editor for JAXenter.com. She received her Bachelor's degree from Monmouth University in Long Branch, New Jersey and is currently enrolled at Goethe University in Frankfurt, Germany where she is working on her Masters. She lives in Frankfurt with her husband and cat.

Leave a Reply

2 Comments on "Introducing Flaggy: A new simple solution for flag packages"

avatar
400
  Subscribe  
Notify of
Eric Greer
Guest

Hey Sarah. Thanks for taking the time to read my post and write this article about flaggy! Day one has been a great success with about 50% of unique viewers staring the project on github.

Gabriela Motroc
Admin

Hi Eric! We’re happy to hear that. If you want to keep in touch, drop us an email at editor@jaxenter.com