How it works...
This recipe attempts to demonstrate most of the common usages of the flag package. It shows custom variable types, a variety of built-in variables, shorthand flags, and writing all flags to a common struct. This is the first recipe to require a main function, as the main usage of flag (flag.Parse()) should be called from main. As a result, the normal example directory is omitted.
The example usage of this application shows that you get -h automatically to get a list of flags that are included. Some other things to note are Boolean flags that are invoked without arguments, and the flag order doesn't matter.
The flag package is a quick way to structure input for command-line applications and provide a flexible means of specifying ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access