Skip to content

Commit

Permalink
i18n/xgettext-go: implement the -D/--directory option of GNU xgettext
Browse files Browse the repository at this point in the history
  • Loading branch information
jhenstridge committed Nov 2, 2020
1 parent b09cc79 commit 92506a3
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion i18n/xgettext-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io/ioutil"
"log"
"os"
"path/filepath"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -170,8 +171,26 @@ func processFiles(args []string) error {
return nil
}

func readContent(fname string) (content []byte, err error) {
// If no search directories have been specified or we have an
// absolute path, just try to read the contents directly.
if len(opts.Directories) == 0 || filepath.IsAbs(fname) {
return ioutil.ReadFile(fname)
}

// Otherwise, search for the file in each of the configured
// directories.
for _, dir := range opts.Directories {
content, err = ioutil.ReadFile(filepath.Join(dir, fname))
if !os.IsNotExist(err) {
break
}
}
return content, err
}

func processSingleGoSource(fset *token.FileSet, fname string) error {
fnameContent, err := ioutil.ReadFile(fname)
fnameContent, err := readContent(fname)
if err != nil {
return err
}
Expand Down Expand Up @@ -277,6 +296,8 @@ msgstr "Project-Id-Version: %s\n"
var opts struct {
FilesFrom string `short:"f" long:"files-from" description:"get list of input files from FILE"`

Directories []string `short:"D" long:"directory" description:"add DIRECTORY to list for input files search"`

Output string `short:"o" long:"output" description:"output to specified file"`

AddComments bool `short:"c" long:"add-comments" description:"place all comment blocks preceding keyword lines in output file"`
Expand Down

0 comments on commit 92506a3

Please sign in to comment.