From 1359ae05c5cad14f0c7e53426f1cf747d9688dbb Mon Sep 17 00:00:00 2001 From: Justin Van Patten Date: Tue, 17 Oct 2023 12:22:05 -0700 Subject: [PATCH] cli: fix generated CLI docs for pulumi/pulumi Create a copy of the open/run command structs before adding them as top-level aliases. This is done because `AddCommand` mutates fields on the Command struct, changing its parent, which causes docs to not be generated correctly from the pulumi/pulumi CLI. --- cmd/esc/cli/esc.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cmd/esc/cli/esc.go b/cmd/esc/cli/esc.go index ce8faec9..d76b0f0a 100644 --- a/cmd/esc/cli/esc.go +++ b/cmd/esc/cli/esc.go @@ -117,8 +117,15 @@ func New(opts *Options) *cobra.Command { env := newEnvCmd(esc) cmd.AddCommand(env) - cmd.AddCommand(getCommand(env, "open")) - cmd.AddCommand(getCommand(env, "run")) + + // Add top-level open/run aliases. We copy the commands to new struct values because + // `AddCommand` mutates the command, modifying its parent, which can cause issues + // with generated docs. + openCmdCopy := *getCommand(env, "open") + runCmdCopy := *getCommand(env, "run") + cmd.AddCommand(&openCmdCopy) + cmd.AddCommand(&runCmdCopy) + cmd.AddCommand(newLoginCmd(esc)) cmd.AddCommand(newLogoutCmd(esc)) cmd.AddCommand(newVersionCmd(esc))