Skip to content

Commit 3f8bc1f

Browse files
committed
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.
1 parent 3115f89 commit 3f8bc1f

File tree

4 files changed

+9
-15
lines changed

4 files changed

+9
-15
lines changed

cmd/gotext/extract.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
// - message rewriting
1616

1717
func init() {
18-
lang = cmdExtract.Flag.String("lang", "en-US", "comma-separated list of languages to process")
18+
cmdExtract.Flag.StringVar(&lang, "lang", lang, "comma-separated list of languages to process")
1919
}
2020

2121
var cmdExtract = &Command{

cmd/gotext/generate.go

-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ import (
88
"golang.org/x/text/message/pipeline"
99
)
1010

11-
func init() {
12-
out = cmdGenerate.Flag.String("out", "", "output file to write to")
13-
}
14-
1511
var cmdGenerate = &Command{
1612
Run: runGenerate,
1713
UsageLine: "generate <package>",

cmd/gotext/main.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ func init() {
3838
var (
3939
srcLang = flag.String("srclang", "en-US", "the source-code language")
4040
dir = flag.String("dir", "locales", "default subdirectory to store translation files")
41+
lang = "en-US"
42+
out string
4143
)
4244

4345
func config() (*pipeline.Config, error) {
@@ -46,10 +48,11 @@ func config() (*pipeline.Config, error) {
4648
return nil, wrap(err, "invalid srclang")
4749
}
4850
return &pipeline.Config{
51+
Dir: *dir,
4952
SourceLanguage: tag,
5053
Supported: getLangs(),
5154
TranslationsPattern: `messages\.(.*)\.json`,
52-
GenFile: *out,
55+
GenFile: out,
5356
}, nil
5457
}
5558

@@ -332,7 +335,7 @@ func help(args []string) {
332335
}
333336

334337
func getLangs() (tags []language.Tag) {
335-
for _, t := range strings.Split(*lang, ",") {
338+
for _, t := range strings.Split(lang, ",") {
336339
if t == "" {
337340
continue
338341
}

cmd/gotext/update.go

+3-8
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,9 @@ import (
1414
// - handle features (gender, plural)
1515
// - message rewriting
1616

17-
var (
18-
lang *string
19-
out *string
20-
)
21-
2217
func init() {
23-
lang = cmdUpdate.Flag.String("lang", "en-US", "comma-separated list of languages to process")
24-
out = cmdUpdate.Flag.String("out", "", "output file to write to")
18+
cmdUpdate.Flag.StringVar(&lang, "lang", lang, "comma-separated list of languages to process")
19+
cmdUpdate.Flag.StringVar(&out, "out", out, "output file to write to")
2520
}
2621

2722
var cmdUpdate = &Command{
@@ -45,7 +40,7 @@ func runUpdate(cmd *Command, config *pipeline.Config, args []string) error {
4540
if err := state.Export(); err != nil {
4641
return wrap(err, "export failed")
4742
}
48-
if *out != "" {
43+
if out != "" {
4944
return wrap(state.Generate(), "generation failed")
5045
}
5146
return nil

0 commit comments

Comments
 (0)