Skip to content

Commit

Permalink
Relative path is now ralative to defined file
Browse files Browse the repository at this point in the history
  • Loading branch information
yuin committed Jul 19, 2023
1 parent 4591604 commit 35ab3b5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
6 changes: 6 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ func LoadConfig(target any, path string) error {
}

func loadMap(path string, fs fs.FS) (m map[any]any, err error) {
if !filepath.IsAbs(path) {
path, err = filepath.Abs(path)
if err != nil {
return
}
}
f, err := fs.Open(path)
if err != nil {
return nil, err
Expand Down
17 changes: 9 additions & 8 deletions gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,8 @@ func (m *Mappers) ConfigLoaded(path string) []error {
if len(m.Destination) == 0 {
errs = append(errs, fmt.Errorf("%s:\t%s.destination must not be empty", m.SourceFile, path))
}
var err error
m.Destination, err = filepath.Abs(m.Destination)
if err != nil {
errs = append(errs, err)
if !filepath.IsAbs(m.Destination) {
m.Destination = filepath.Join(filepath.Dir(m.SourceFile), m.Destination)
}
return errs
}
Expand Down Expand Up @@ -137,10 +135,8 @@ func (m *Mapping) ConfigLoaded(path string) []error {
if len(m.Destination) == 0 {
errs = append(errs, fmt.Errorf("%s:\t%s.destination must not be empty", m.SourceFile, path))
}
var err error
m.Destination, err = filepath.Abs(m.Destination)
if err != nil {
errs = append(errs, err)
if !filepath.IsAbs(m.Destination) {
m.Destination = filepath.Join(filepath.Dir(m.SourceFile), m.Destination)
}
if len(m.Package) == 0 {
m.Package = filepath.Base(m.Destination)
Expand Down Expand Up @@ -229,6 +225,11 @@ func (m *MappingOperand) ConfigLoaded(path string) []error {
if len(m.Name) == 0 {
errs = append(errs, fmt.Errorf("%s:\t%s.name must not be empty", m.SourceFile, path))
}

if !filepath.IsAbs(m.Package) {
m.Package = filepath.Join(filepath.Dir(m.SourceFile), m.Package)
}

return errs
}

Expand Down

0 comments on commit 35ab3b5

Please sign in to comment.