diff options
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 |