Skip to content

Commit

Permalink
yajsv: Resolve file list relative to its dir
Browse files Browse the repository at this point in the history
  • Loading branch information
neilpa committed Jan 31, 2020
1 parent c31e5c9 commit caf6fa2
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var (
)

func init() {
flag.Var(&listFlags, "l", "validate JSON documents from newline separated list of paths and/or globs in a text file")
flag.Var(&listFlags, "l", "validate JSON documents from newline separated paths and/or globs in a text file (relative to the basename of the file itself)")
flag.Var(&refFlags, "r", "referenced schema(s), can be globs and/or used multiple times")
flag.Usage = printUsage
}
Expand All @@ -53,14 +53,17 @@ func main() {
docs = append(docs, glob(arg)...)
}
for _, list := range listFlags {
dir := filepath.Dir(list)
f, err := os.Open(list)
if err != nil {
log.Fatalf("%s: %s\n", list, err)
}
defer f.Close()

scanner := bufio.NewScanner(f)
for scanner.Scan() {
pattern := strings.TrimSpace(scanner.Text())
// Calclate the glob relative to the directory of the file list
pattern := filepath.Join(dir, strings.TrimSpace(scanner.Text()))
docs = append(docs, glob(pattern)...)
}
if err := scanner.Err(); err != nil {
Expand Down

0 comments on commit caf6fa2

Please sign in to comment.