aboutsummaryrefslogtreecommitdiffstats
path: root/doc.go
diff options
context:
space:
mode:
authorEugene Triguba <hello@eugenetriguba.com>2025-12-27 17:05:01 -0500
committerEugene Triguba <hello@eugenetriguba.com>2025-12-27 17:05:01 -0500
commit7d3da0e6851240a8b701ef01c88a2cba6ebc96ff (patch)
treeb74a831cd34a57cf7fe9f86f826c0d3e6e801874 /doc.go
parentRelease v0.4.0 (diff)
downloadsubcmd-7d3da0e6851240a8b701ef01c88a2cba6ebc96ff.zip
Use internal flagset within the registry
Diffstat (limited to 'doc.go')
-rw-r--r--doc.go21
1 files changed, 11 insertions, 10 deletions
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