From 3f8bc1f8743a9bcfcd862596808858023bfa2c3f Mon Sep 17 00:00:00 2001 From: Richard Shaffer Date: Mon, 24 May 2021 20:34:20 -0700 Subject: [PATCH] Fix command line options to gotext: * 'dir' was not hooked up to anything. * 'lang' was assigned to twice, once by the init() in extract.go and again in the init() in update.go. That caused one of them to not work. --- cmd/gotext/extract.go | 2 +- cmd/gotext/generate.go | 4 ---- cmd/gotext/main.go | 7 +++++-- cmd/gotext/update.go | 11 +++-------- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/cmd/gotext/extract.go b/cmd/gotext/extract.go index 103d7e600..f07b6a9b6 100644 --- a/cmd/gotext/extract.go +++ b/cmd/gotext/extract.go @@ -15,7 +15,7 @@ import ( // - message rewriting func init() { - lang = cmdExtract.Flag.String("lang", "en-US", "comma-separated list of languages to process") + cmdExtract.Flag.StringVar(&lang, "lang", lang, "comma-separated list of languages to process") } var cmdExtract = &Command{ diff --git a/cmd/gotext/generate.go b/cmd/gotext/generate.go index 36820df8a..1e49bb802 100644 --- a/cmd/gotext/generate.go +++ b/cmd/gotext/generate.go @@ -8,10 +8,6 @@ import ( "golang.org/x/text/message/pipeline" ) -func init() { - out = cmdGenerate.Flag.String("out", "", "output file to write to") -} - var cmdGenerate = &Command{ Run: runGenerate, UsageLine: "generate ", diff --git a/cmd/gotext/main.go b/cmd/gotext/main.go index f31dd4fbd..3e945919f 100644 --- a/cmd/gotext/main.go +++ b/cmd/gotext/main.go @@ -38,6 +38,8 @@ func init() { var ( srcLang = flag.String("srclang", "en-US", "the source-code language") dir = flag.String("dir", "locales", "default subdirectory to store translation files") + lang = "en-US" + out string ) func config() (*pipeline.Config, error) { @@ -46,10 +48,11 @@ func config() (*pipeline.Config, error) { return nil, wrap(err, "invalid srclang") } return &pipeline.Config{ + Dir: *dir, SourceLanguage: tag, Supported: getLangs(), TranslationsPattern: `messages\.(.*)\.json`, - GenFile: *out, + GenFile: out, }, nil } @@ -332,7 +335,7 @@ func help(args []string) { } func getLangs() (tags []language.Tag) { - for _, t := range strings.Split(*lang, ",") { + for _, t := range strings.Split(lang, ",") { if t == "" { continue } diff --git a/cmd/gotext/update.go b/cmd/gotext/update.go index 1260750cc..a6913c1dd 100644 --- a/cmd/gotext/update.go +++ b/cmd/gotext/update.go @@ -14,14 +14,9 @@ import ( // - handle features (gender, plural) // - message rewriting -var ( - lang *string - out *string -) - func init() { - lang = cmdUpdate.Flag.String("lang", "en-US", "comma-separated list of languages to process") - out = cmdUpdate.Flag.String("out", "", "output file to write to") + cmdUpdate.Flag.StringVar(&lang, "lang", lang, "comma-separated list of languages to process") + cmdUpdate.Flag.StringVar(&out, "out", out, "output file to write to") } var cmdUpdate = &Command{ @@ -45,7 +40,7 @@ func runUpdate(cmd *Command, config *pipeline.Config, args []string) error { if err := state.Export(); err != nil { return wrap(err, "export failed") } - if *out != "" { + if out != "" { return wrap(state.Generate(), "generation failed") } return nil