From f601318df7726bb608d57166bde3c685494c7841 Mon Sep 17 00:00:00 2001 From: aiyijing Date: Sun, 9 Jul 2023 22:53:00 +0800 Subject: [PATCH 1/4] fix subcommand cannot be translated Signed-off-by: aiyijing --- cmd/minikube/cmd/root.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/cmd/minikube/cmd/root.go b/cmd/minikube/cmd/root.go index 3d3958a1c7..6d0f3cbb0c 100644 --- a/cmd/minikube/cmd/root.go +++ b/cmd/minikube/cmd/root.go @@ -140,7 +140,7 @@ func Execute() { } } - for _, c := range RootCmd.Commands() { + visitAllCommand(RootCmd, func(c *cobra.Command) { c.Short = translate.T(c.Short) c.Long = translate.T(c.Long) c.Flags().VisitAll(func(f *pflag.Flag) { @@ -148,7 +148,8 @@ func Execute() { }) c.SetUsageTemplate(usageTemplate()) - } + }) + RootCmd.Short = translate.T(RootCmd.Short) RootCmd.Long = translate.T(RootCmd.Long) RootCmd.Flags().VisitAll(func(f *pflag.Flag) { @@ -340,3 +341,13 @@ func addToPath(dir string) { func validateUsername(name string) bool { return len(name) <= 60 } + +// visitAllCommand visit all command include subCommand +func visitAllCommand(cmd *cobra.Command, f func(subCmd *cobra.Command)) { + for _, c := range cmd.Commands() { + f(c) + if c.HasSubCommands() { + visitAllCommand(c, f) + } + } +} From 67c3d13f1fe91270bc9fe4837e3b3a7836bf72eb Mon Sep 17 00:00:00 2001 From: AiYijing Date: Thu, 13 Jul 2023 06:36:09 +0800 Subject: [PATCH 2/4] Update cmd/minikube/cmd/root.go Co-authored-by: Steven Powell <44844360+spowelljr@users.noreply.github.com> --- cmd/minikube/cmd/root.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/minikube/cmd/root.go b/cmd/minikube/cmd/root.go index 6d0f3cbb0c..a87d96b87b 100644 --- a/cmd/minikube/cmd/root.go +++ b/cmd/minikube/cmd/root.go @@ -342,8 +342,8 @@ func validateUsername(name string) bool { return len(name) <= 60 } -// visitAllCommand visit all command include subCommand -func visitAllCommand(cmd *cobra.Command, f func(subCmd *cobra.Command)) { +// applyToAllCommands applies the provided func to all commands including sub commands +func applyToAllCommands(cmd *cobra.Command, f func(subCmd *cobra.Command)) { for _, c := range cmd.Commands() { f(c) if c.HasSubCommands() { From 164a522b605c74c2f0a39a4aa2b60f50c8439913 Mon Sep 17 00:00:00 2001 From: AiYijing Date: Thu, 13 Jul 2023 06:39:32 +0800 Subject: [PATCH 3/4] Update cmd/minikube/cmd/root.go Co-authored-by: Steven Powell <44844360+spowelljr@users.noreply.github.com> --- cmd/minikube/cmd/root.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/minikube/cmd/root.go b/cmd/minikube/cmd/root.go index a87d96b87b..b04272ae50 100644 --- a/cmd/minikube/cmd/root.go +++ b/cmd/minikube/cmd/root.go @@ -140,7 +140,7 @@ func Execute() { } } - visitAllCommand(RootCmd, func(c *cobra.Command) { + applyToAllCommands(RootCmd, func(c *cobra.Command) { c.Short = translate.T(c.Short) c.Long = translate.T(c.Long) c.Flags().VisitAll(func(f *pflag.Flag) { From b8801c3306ce7bfb55e31adbc4c508dd865f93fe Mon Sep 17 00:00:00 2001 From: Steven Powell <44844360+spowelljr@users.noreply.github.com> Date: Wed, 12 Jul 2023 16:10:55 -0700 Subject: [PATCH 4/4] Update cmd/minikube/cmd/root.go --- cmd/minikube/cmd/root.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/minikube/cmd/root.go b/cmd/minikube/cmd/root.go index b04272ae50..e53f6909c2 100644 --- a/cmd/minikube/cmd/root.go +++ b/cmd/minikube/cmd/root.go @@ -347,7 +347,7 @@ func applyToAllCommands(cmd *cobra.Command, f func(subCmd *cobra.Command)) { for _, c := range cmd.Commands() { f(c) if c.HasSubCommands() { - visitAllCommand(c, f) + applyToAllCommands(c, f) } } }