The flag package

Flags are specially-formatted strings that are passed into a program to control its behavior. Dealing with flags on your own might become very difficult if you want to support multiple flags. Thus, if you are developing UNIX system command-line utilities, you will find the flag package very interesting and useful.

The flag package makes no assumptions about the order of command-line arguments and options, and it prints helpful messages in case there was an error in the way the command-line utility was executed.

The biggest advantage of the flag package is that it is part of the standard Go library, which means that it has been extensively tested and debugged.

I will present two Go programs that use the flag package: a ...

Get Mastering Go - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.