Skip to content

Commit

Permalink
Make sure the first argument has the right file extension to prevent …
Browse files Browse the repository at this point in the history
…confusing errors when accidentally using it on other files
  • Loading branch information
sdassow committed Oct 27, 2024
1 parent 525d866 commit 5af73a8
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions cmd/fyne/internal/commands/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,13 @@ func Translate() *cli.Command {
},
},
Action: func(ctx *cli.Context) error {
translationsFile := ctx.Args().First()
opts := translateOpts{
DryRun: ctx.Bool("dry-run"),
Update: ctx.Bool("update"),
Verbose: ctx.Bool("verbose"),
}

if translationsFile == "" {
fmt.Fprintln(os.Stderr, "Missing argument: translationsFile")
usage := func() {
fmt.Fprintf(os.Stderr, "usage: %s %s [command options] %s\n",
ctx.App.Name,
ctx.Command.Name,
Expand All @@ -62,6 +60,17 @@ func Translate() *cli.Command {
os.Exit(1)
}

translationsFile := ctx.Args().First()
if translationsFile == "" {
fmt.Fprintln(os.Stderr, "Missing argument: translationsFile")
usage()
}

if translationsFile != "-" && filepath.Ext(translationsFile) != ".json" {
fmt.Fprintln(os.Stderr, "Need .json extension for translationsFile")
usage()
}

sources, err := findSources(ctx.Args().Tail(), ".go", ".")
if err != nil {
return err
Expand Down

0 comments on commit 5af73a8

Please sign in to comment.