Skip to content

Commit 3defc2f

Browse files
committed
Support modify the preHook args
1 parent 9e4ae91 commit 3defc2f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

pkg/cmd/root.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func Execute(cmd *cobra.Command, target string, aliasList []pkg.Alias, preHook f
124124
ExecuteContext(cmd, context.TODO(), target, aliasList, preHook)
125125
}
126126

127-
func ExecuteContext(cmd *cobra.Command, ctx context.Context, target string, aliasList []pkg.Alias, preHook func([]string)) {
127+
func ExecuteContextV2(cmd *cobra.Command, ctx context.Context, target string, aliasList []pkg.Alias, preHook func([]string)[]string) {
128128
cmd.SilenceErrors = true
129129
var err error
130130
// this is very trick way, looking to improve it
@@ -164,7 +164,7 @@ func ExecuteContext(cmd *cobra.Command, ctx context.Context, target string, alia
164164
}
165165

166166
if preHook != nil {
167-
preHook(args)
167+
args = preHook(args)
168168
}
169169

170170
targetArgs = append(targetCmdArray, args...)
@@ -177,3 +177,12 @@ func ExecuteContext(cmd *cobra.Command, ctx context.Context, target string, alia
177177
}
178178
}
179179
}
180+
181+
func ExecuteContext(cmd *cobra.Command, ctx context.Context, target string, aliasList []pkg.Alias, preHook func([]string)) {
182+
ExecuteContextV2(cmd, ctx, target, aliasList, func(i []string) []string {
183+
if preHook != nil {
184+
preHook(i)
185+
}
186+
return i
187+
})
188+
}

0 commit comments

Comments
 (0)