From 7d3da0e6851240a8b701ef01c88a2cba6ebc96ff Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sat, 27 Dec 2025 17:05:01 -0500 Subject: Use internal flagset within the registry --- doc.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'doc.go') diff --git a/doc.go b/doc.go index eccb871..d38be35 100644 --- a/doc.go +++ b/doc.go @@ -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 -- cgit v1.2.3