Skip to content

Commit 085433c

Browse files
authored
Merge pull request #16852 from aiyijing/fix/subcmd-unable-translate
fix subcommand cannot be translated
2 parents 7bf84ec + b8801c3 commit 085433c

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

cmd/minikube/cmd/root.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,16 @@ func Execute() {
140140
}
141141
}
142142

143-
for _, c := range RootCmd.Commands() {
143+
applyToAllCommands(RootCmd, func(c *cobra.Command) {
144144
c.Short = translate.T(c.Short)
145145
c.Long = translate.T(c.Long)
146146
c.Flags().VisitAll(func(f *pflag.Flag) {
147147
f.Usage = translate.T(f.Usage)
148148
})
149149

150150
c.SetUsageTemplate(usageTemplate())
151-
}
151+
})
152+
152153
RootCmd.Short = translate.T(RootCmd.Short)
153154
RootCmd.Long = translate.T(RootCmd.Long)
154155
RootCmd.Flags().VisitAll(func(f *pflag.Flag) {
@@ -341,3 +342,13 @@ func addToPath(dir string) {
341342
func validateUsername(name string) bool {
342343
return len(name) <= 60
343344
}
345+
346+
// applyToAllCommands applies the provided func to all commands including sub commands
347+
func applyToAllCommands(cmd *cobra.Command, f func(subCmd *cobra.Command)) {
348+
for _, c := range cmd.Commands() {
349+
f(c)
350+
if c.HasSubCommands() {
351+
applyToAllCommands(c, f)
352+
}
353+
}
354+
}

0 commit comments

Comments
 (0)