diff options
| author | Eugene Triguba <hello@eugenetriguba.com> | 2025-12-27 17:05:01 -0500 |
|---|---|---|
| committer | Eugene Triguba <hello@eugenetriguba.com> | 2025-12-27 17:05:01 -0500 |
| commit | 7d3da0e6851240a8b701ef01c88a2cba6ebc96ff (patch) | |
| tree | b74a831cd34a57cf7fe9f86f826c0d3e6e801874 /doc.go | |
| parent | Release v0.4.0 (diff) | |
| download | subcmd-7d3da0e6851240a8b701ef01c88a2cba6ebc96ff.zip | |
Use internal flagset within the registry
Diffstat (limited to 'doc.go')
| -rw-r--r-- | doc.go | 21 |
1 files changed, 11 insertions, 10 deletions
@@ -33,16 +33,9 @@ // } // // func main() { -// // Register commands // subcmd.Register(&greetCmd{}, "") // subcmd.Register(subcmd.HelpCommand(), "") -// -// // Parse top-level flags -// flag.Parse() -// -// // Execute the subcommand -// ctx := context.Background() -// os.Exit(int(subcmd.Execute(ctx))) +// os.Exit(int(subcmd.Execute(context.Background()))) // } // // # Command Groups @@ -67,11 +60,19 @@ // While the package provides a default registry for convenience, you can // create custom registries for more control: // -// registry := subcmd.NewRegistry() +// registry := subcmd.NewRegistry(subcmd.WithOutput(customWriter)) // registry.Register(&myCmd{}, "") -// registry.SetOutput(customWriter) // status := registry.Execute(ctx) // // This is useful for testing or when building applications that need multiple // independent command sets. +// +// # Top-level Flags +// +// To add top-level flags (flags that apply before the subcommand), use the +// Flags() accessor: +// +// verbose := subcmd.Flags().Bool("v", false, "verbose output") +// subcmd.Register(&myCmd{}, "") +// os.Exit(int(subcmd.Execute(context.Background()))) package subcmd |