From f759d8496e0749d187891e8eb8fac7105be0d8a3 Mon Sep 17 00:00:00 2001 From: Shirong Lu <73147033+happysnaker@users.noreply.github.com> Date: Fri, 3 Jul 2026 22:36:12 +0800 Subject: [PATCH] feat: add Parent() accessor to Command (fixes #2372) --- command.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/command.go b/command.go index 4cd907a558..8fef2f3d3c 100644 --- a/command.go +++ b/command.go @@ -337,6 +337,11 @@ func (cmd *Command) argsWithDefaultCommand(oldArgs Args) Args { } // Root returns the Command at the root of the graph +// Parent returns the parent command, or nil if this is the root command. +func (cmd *Command) Parent() *Command { + return cmd.parent +} + func (cmd *Command) Root() *Command { if cmd.parent == nil { return cmd