|
1 | | -// Package cli provides a lightweight framework for building command-line applications. It features |
2 | | -// nested subcommand support and flexible flag parsing. |
| 1 | +// Package cli provides a lightweight framework for building command-line applications using Go's |
| 2 | +// standard library flag package. It extends flag functionality to support flags anywhere in command |
| 3 | +// arguments. |
3 | 4 | // |
4 | | -// The package prioritizes simplicity and ease of use, making it an ideal foundation for CLI |
5 | | -// applications that don't require the overhead of larger frameworks. This focused design allows |
6 | | -// developers to concentrate on their application's core functionality while keeping their code |
7 | | -// simple and maintainable. |
| 5 | +// Key features: |
| 6 | +// - Nested subcommands for organizing complex CLIs |
| 7 | +// - Flexible flag parsing, allowing flags anywhere in arguments |
| 8 | +// - Parent-to-child flag inheritance |
| 9 | +// - Type-safe flag access |
| 10 | +// - Automatic help text generation |
| 11 | +// - Command suggestions for misspelled inputs |
| 12 | +// |
| 13 | +// Quick example: |
| 14 | +// |
| 15 | +// root := &cli.Command{ |
| 16 | +// Name: "echo", |
| 17 | +// Usage: "echo [flags] <text>...", |
| 18 | +// ShortHelp: "prints the provided text", |
| 19 | +// Flags: cli.FlagsFunc(func(f *flag.FlagSet) { |
| 20 | +// f.Bool("c", false, "capitalize the input") |
| 21 | +// }), |
| 22 | +// Exec: func(ctx context.Context, s *cli.State) error { |
| 23 | +// output := strings.Join(s.Args, " ") |
| 24 | +// if cli.GetFlag[bool](s, "c") { |
| 25 | +// output = strings.ToUpper(output) |
| 26 | +// } |
| 27 | +// fmt.Fprintln(s.Stdout, output) |
| 28 | +// return nil |
| 29 | +// }, |
| 30 | +// } |
| 31 | +// |
| 32 | +// The package intentionally maintains a minimal API surface to serve as a building block for CLI |
| 33 | +// applications while leveraging the standard library's flag package. This approach enables |
| 34 | +// developers to build maintainable command-line tools quickly while focusing on application logic |
| 35 | +// rather than framework complexity. |
8 | 36 | package cli |
0 commit comments