A small Go command-line program can use the standard-library `flag` package to define options, parse their values, and generate help text. Register each flag before calling `flag.Parse()`, then read the resulting value. section 2.1.1
A greeting with two flags
```go package main import ( "flag" "fmt" ) func main() { name := flag.String("name", "World", "A name to say hello to.") var inSpanish bool flag.BoolVar(&inSpanish, "spanish", false, "Use Spanish language.") flag.BoolVar(&inSpanish, "s", false, "Use Spanish language.") flag.Parse() if inSpanish { fmt.Printf("Hola %s!\n", *name) } else { fmt.Printf("Hello %s!\n", *name) } } ``` `flag.String` returns a pointer, so the greeting reads `*name`. `flag.BoolVar` instead stores a parsed value in an existing variable. Registering both `spanish` and `s` against `inSpanish` provides two explicit names for the same choice. section 2.1.1
Keep the built-in syntax in mind:
- A flag can begin with `-` or `--`; the package does not assign separate short- and long-option meanings to those prefixes. section 2.1.1
- Each flag is separate. Grouped short options such as `-la` are not supported by the built-in behavior. section 2.1.1 section 2.1.4
- Typed registration functions follow a similar pattern for other basic value types; `StringVar` and `IntVar`, for instance, store values in supplied variables. section 2.1.1
Descriptions supplied during registration appear in generated usage output, alongside flag names and applicable defaults. An invalid flag can reveal that output. For a different presentation, `flag.VisitAll` lets you iterate over registered flags and format their names, descriptions, and default values yourself. section 2.1.1
Listing 2.4 Custom flag help text
flag.VisitAll(func(flag *flag.Flag) {
format := "\t-%s: %s (Default: '%s')\n"
fmt.Printf(format, flag.Name, flag.Usage, flag.DefValue)
})
The `VisitAll` listing shows custom help formatting with each flag’s `Name`, `Usage`, and `DefValue`. section 2.1.1
For a CLI whose users expect grouped UNIX-style short options or a richer command interface, consider a command-line library rather than maintaining a modified flag parser. Cobra is one shown alternative: it defines explicit long and short flag names and supports commands. section 2.1.4



