Last Updated: May 22, 2026
Almost every command-line tool needs to read options: a port number, a config path, a verbosity level, a date range. Go's standard library ships the flag package for exactly this job, and it's enough to build production CLIs without ever pulling in a third-party library. This chapter walks through how flag parses arguments, the two ways to declare flags, how to handle positional arguments, how to customize help output, how to wire up subcommands by hand, and how to plug in custom value types.