@@ -97,7 +97,7 @@ func New(l log.Logger, opts *options.TerragruntOptions) cli.Commands {
9797 dag .NewCommand (l , opts ), // dag
9898 render .NewCommand (l , opts ), // render
9999 helpcmd .NewCommand (l , opts ), // help (hidden)
100- versioncmd .NewCommand (opts ), // version (hidden)
100+ versioncmd .NewCommand (), // version (hidden)
101101 awsproviderpatch .NewCommand (l , opts ), // aws-provider-patch (hidden)
102102 }.SetCategory (
103103 & cli.Category {
@@ -123,26 +123,24 @@ func New(l log.Logger, opts *options.TerragruntOptions) cli.Commands {
123123}
124124
125125// WrapWithTelemetry wraps CLI command execution with setting of telemetry context and labels, if telemetry is disabled, just runAction the command.
126- func WrapWithTelemetry (l log.Logger , opts * options.TerragruntOptions ) func (ctx * cli.Context , action cli.ActionFunc ) error {
127- return func (ctx * cli.Context , action cli.ActionFunc ) error {
128- return telemetry .TelemeterFromContext (ctx ).Collect (ctx . Context , fmt .Sprintf ("%s %s" , ctx .Command .Name , opts .TerraformCommand ), map [string ]any {
126+ func WrapWithTelemetry (l log.Logger , opts * options.TerragruntOptions ) func (ctx context. Context , cliCtx * cli.Context , action cli.ActionFunc ) error {
127+ return func (ctx context. Context , cliCtx * cli.Context , action cli.ActionFunc ) error {
128+ return telemetry .TelemeterFromContext (ctx ).Collect (ctx , fmt .Sprintf ("%s %s" , cliCtx .Command .Name , opts .TerraformCommand ), map [string ]any {
129129 "terraformCommand" : opts .TerraformCommand ,
130130 "args" : opts .TerraformCliArgs ,
131131 "dir" : opts .WorkingDir ,
132132 }, func (childCtx context.Context ) error {
133- ctx .Context = childCtx //nolint:fatcontext
134- if err := initialSetup (ctx , l , opts ); err != nil {
133+ if err := initialSetup (cliCtx , l , opts ); err != nil {
135134 return err
136135 }
137136
138- // TODO: See if this lint should be ignored
139- return runAction (ctx , l , opts , action ) //nolint:contextcheck
137+ return runAction (childCtx , cliCtx , l , opts , action )
140138 })
141139 }
142140}
143141
144- func runAction (cliCtx * cli.Context , l log.Logger , opts * options.TerragruntOptions , action cli.ActionFunc ) error {
145- ctx , cancel := context .WithCancel (cliCtx . Context )
142+ func runAction (ctx context. Context , cliCtx * cli.Context , l log.Logger , opts * options.TerragruntOptions , action cli.ActionFunc ) error {
143+ ctx , cancel := context .WithCancel (ctx )
146144 defer cancel ()
147145
148146 errGroup , ctx := errgroup .WithContext (ctx )
@@ -154,6 +152,9 @@ func runAction(cliCtx *cli.Context, l log.Logger, opts *options.TerragruntOption
154152 }
155153 }
156154
155+ // actionCtx is the context passed to the action, which may be wrapped with hooks
156+ actionCtx := ctx
157+
157158 // Run provider cache server
158159 if opts .ProviderCache {
159160 server , err := providercache .InitServer (l , opts )
@@ -167,7 +168,7 @@ func runAction(cliCtx *cli.Context, l log.Logger, opts *options.TerragruntOption
167168 }
168169 defer ln .Close () //nolint:errcheck
169170
170- cliCtx . Context = tf .ContextWithTerraformCommandHook (ctx , server .TerraformCommandHook )
171+ actionCtx = tf .ContextWithTerraformCommandHook (ctx , server .TerraformCommandHook )
171172
172173 errGroup .Go (func () error {
173174 return server .Run (ctx , ln )
@@ -179,7 +180,7 @@ func runAction(cliCtx *cli.Context, l log.Logger, opts *options.TerragruntOption
179180 defer cancel ()
180181
181182 if action != nil {
182- return action (cliCtx )
183+ return action (actionCtx , cliCtx )
183184 }
184185
185186 return nil
0 commit comments