aboutsummaryrefslogtreecommitdiffhomepage
path: root/command/builder.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-02-23 00:55:18 +0900
committerOphestra <cat@gensokyo.uk>2025-02-23 00:55:18 +0900
commit312753924be1109a22269ebde81fa244ef9b6379 (patch)
tree4d2d7e4f1b07f675eeac82dad55478714981a597 /command/builder.go
parent54308f79d206f89807aba3bc998fc770d01efed1 (diff)
command: root early handler func special case
This allows for early initialisation with access to flags on the root node. This can be useful for configuring global state used by subcommands. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'command/builder.go')
-rw-r--r--command/builder.go6
1 files changed, 4 insertions, 2 deletions
diff --git a/command/builder.go b/command/builder.go
index 5c9b4de9..c0782c66 100644
--- a/command/builder.go
+++ b/command/builder.go
@@ -7,8 +7,10 @@ import (
)
// New initialises a root Node.
-func New(output io.Writer, logf LogFunc, name string) Command {
- return rootNode{newNode(output, logf, name, "")}
+func New(output io.Writer, logf LogFunc, name string, early HandlerFunc) Command {
+ c := rootNode{newNode(output, logf, name, "")}
+ c.f = early
+ return c
}
func newNode(output io.Writer, logf LogFunc, name, usage string) *node {