fix(i18n): remove an ugly hack

This commit is contained in:
Goutte 2023-04-04 11:39:07 +02:00
parent 102ab5b544
commit 775014c459
2 changed files with 10 additions and 4 deletions

View file

@ -252,8 +252,6 @@ type Command struct {
// SuggestionsMinimumDistance defines minimum levenshtein distance to display suggestions. // SuggestionsMinimumDistance defines minimum levenshtein distance to display suggestions.
// Must be > 0. // Must be > 0.
SuggestionsMinimumDistance int SuggestionsMinimumDistance int
I18n *i18nCommandGlossary
} }
// Context returns underlying command context. If command was executed // Context returns underlying command context. If command was executed
@ -434,7 +432,11 @@ func (c *Command) UsageFunc() (f func(*Command) error) {
} }
return func(c *Command) error { return func(c *Command) error {
c.mergePersistentFlags() c.mergePersistentFlags()
err := tmpl(c.OutOrStderr(), c.UsageTemplate(), c) data := CommandUsageTemplateData{
Command: c,
I18n: getCommandGlossary(),
}
err := tmpl(c.OutOrStderr(), c.UsageTemplate(), data)
if err != nil { if err != nil {
c.PrintErrln(err) c.PrintErrln(err)
} }
@ -544,7 +546,6 @@ func (c *Command) NamePadding() int {
// UsageTemplate returns usage template for the command. // UsageTemplate returns usage template for the command.
func (c *Command) UsageTemplate() string { func (c *Command) UsageTemplate() string {
c.I18n = getCommandGlossary()
if c.usageTemplate != "" { if c.usageTemplate != "" {
return c.usageTemplate return c.usageTemplate
} }

View file

@ -40,6 +40,11 @@ type i18nCommandGlossary struct {
ForInfoAboutCommand string ForInfoAboutCommand string
} }
type CommandUsageTemplateData struct {
*Command
I18n *i18nCommandGlossary
}
var commonCommandGlossary *i18nCommandGlossary var commonCommandGlossary *i18nCommandGlossary
func getCommandGlossary() *i18nCommandGlossary { func getCommandGlossary() *i18nCommandGlossary {