Merge pull request #16852 from aiyijing/fix/subcmd-unable-translate
fix subcommand cannot be translatedpull/16878/head
commit
085433cd1b
|
@ -140,7 +140,7 @@ func Execute() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range RootCmd.Commands() {
|
applyToAllCommands(RootCmd, func(c *cobra.Command) {
|
||||||
c.Short = translate.T(c.Short)
|
c.Short = translate.T(c.Short)
|
||||||
c.Long = translate.T(c.Long)
|
c.Long = translate.T(c.Long)
|
||||||
c.Flags().VisitAll(func(f *pflag.Flag) {
|
c.Flags().VisitAll(func(f *pflag.Flag) {
|
||||||
|
@ -148,7 +148,8 @@ func Execute() {
|
||||||
})
|
})
|
||||||
|
|
||||||
c.SetUsageTemplate(usageTemplate())
|
c.SetUsageTemplate(usageTemplate())
|
||||||
}
|
})
|
||||||
|
|
||||||
RootCmd.Short = translate.T(RootCmd.Short)
|
RootCmd.Short = translate.T(RootCmd.Short)
|
||||||
RootCmd.Long = translate.T(RootCmd.Long)
|
RootCmd.Long = translate.T(RootCmd.Long)
|
||||||
RootCmd.Flags().VisitAll(func(f *pflag.Flag) {
|
RootCmd.Flags().VisitAll(func(f *pflag.Flag) {
|
||||||
|
@ -341,3 +342,13 @@ func addToPath(dir string) {
|
||||||
func validateUsername(name string) bool {
|
func validateUsername(name string) bool {
|
||||||
return len(name) <= 60
|
return len(name) <= 60
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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() {
|
||||||
|
applyToAllCommands(c, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue