From 775014c459a724f92161edea6eee663a3438a6bd Mon Sep 17 00:00:00 2001 From: Goutte Date: Tue, 4 Apr 2023 11:39:07 +0200 Subject: [PATCH] fix(i18n): remove an ugly hack --- command.go | 9 +++++---- localizer.go | 5 +++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/command.go b/command.go index 595b5b5f..406106a8 100644 --- a/command.go +++ b/command.go @@ -252,8 +252,6 @@ type Command struct { // SuggestionsMinimumDistance defines minimum levenshtein distance to display suggestions. // Must be > 0. SuggestionsMinimumDistance int - - I18n *i18nCommandGlossary } // 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 { 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 { c.PrintErrln(err) } @@ -544,7 +546,6 @@ func (c *Command) NamePadding() int { // UsageTemplate returns usage template for the command. func (c *Command) UsageTemplate() string { - c.I18n = getCommandGlossary() if c.usageTemplate != "" { return c.usageTemplate } diff --git a/localizer.go b/localizer.go index c1971869..3d208583 100644 --- a/localizer.go +++ b/localizer.go @@ -40,6 +40,11 @@ type i18nCommandGlossary struct { ForInfoAboutCommand string } +type CommandUsageTemplateData struct { + *Command + I18n *i18nCommandGlossary +} + var commonCommandGlossary *i18nCommandGlossary func getCommandGlossary() *i18nCommandGlossary {