Skip to content

Commit

Permalink
Report source as start line, not end
Browse files Browse the repository at this point in the history
  • Loading branch information
pjeby authored and cespare committed Jun 2, 2018
1 parent 8042f36 commit bf9932c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions config.go
Expand Up @@ -89,6 +89,10 @@ parseFile:

// Found a command line; begin parsing it
errorf := fmt.Sprintf("error on line %d of %s: %%s", lineNo, name)

c := &Config{}
c.source = fmt.Sprintf("%s, line %d", name, lineNo)

line := scanner.Text()
parts, err := shellquote.Split(line)

Expand All @@ -112,16 +116,13 @@ parseFile:
parts, err = shellquote.Split(line)
}

c := &Config{}
flags := flag.NewFlagSet("", flag.ContinueOnError)
flags.SetOutput(ioutil.Discard)
c.registerFlags(flags)

if err := flags.Parse(parts); err != nil {
return nil, fmt.Errorf(errorf, err)
}
c.command = flags.Args()
c.source = fmt.Sprintf("%s, line %d", name, lineNo)
configs = append(configs, c)
}
if err := scanner.Err(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion config_test.go
Expand Up @@ -53,7 +53,7 @@ world"
},
{
command: []string{"echo", "hello\nworld"},
source: "test input, line 10",
source: "test input, line 8",
regexes: []string{"foo", "bar"},
globs: []string{"a"},
inverseRegexes: []string{"baz"},
Expand Down

0 comments on commit bf9932c

Please sign in to comment.