1
1
mirror of https://github.com/wader/fq.git synced 2024-11-27 14:14:58 +03:00

interp: Make include abs path work again

This commit is contained in:
Mattias Wadman 2021-10-26 11:02:30 +02:00
parent 1d83554b4a
commit 826c8bd555
2 changed files with 8 additions and 0 deletions

View File

@ -585,11 +585,17 @@ func (i *Interp) Eval(ctx context.Context, c interface{}, src string, srcFilenam
{
"", false, func(filename string) (io.Reader, error) {
// TODO: jq $ORIGIN
if filepath.IsAbs(filename) {
return i.os.FS().Open(filename)
}
for _, path := range append([]string{"./"}, i.includePaths()...) {
if f, err := i.os.FS().Open(filepath.Join(path, filename)); err == nil {
return f, nil
}
}
return nil, &fs.PathError{Op: "open", Path: filename, Err: fs.ErrNotExist}
},
},

View File

@ -6,6 +6,8 @@ $ fq --include-path /library -n 'include "a"; a'
"a"
$ fq -L /wrong -L /library -n 'include "a"; a'
"a"
$ fq -n 'include "/library/a"; a'
"a"
$ fq -L /wrong -n 'include "a"; a'
exitcode: 3
stderr: