From af30e5e6ba8d7763ec07fd726bd0e8e918e99929 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Wed, 8 Jan 2020 06:49:54 +1100 Subject: [PATCH] load linuxdb from relative path --- cmd/fs.go | 10 ++++++++++ cmd/linuxdb.go | 8 +++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cmd/fs.go b/cmd/fs.go index d0ceae7c5..36109e8f7 100644 --- a/cmd/fs.go +++ b/cmd/fs.go @@ -132,6 +132,16 @@ func (fs *FSHelper) LocalDir(dir string) (*Dir, error) { }, err } +// LoadRelativeFile loads the given file relative to the caller's directory +func (fs *FSHelper) LoadRelativeFile(relativePath string) ([]byte, error) { + _, filename, _, _ := runtime.Caller(0) + fullPath, err := filepath.Abs(filepath.Join(path.Dir(filename), relativePath)) + if err != nil { + return nil, err + } + return ioutil.ReadFile(fullPath) +} + // GetSubdirs will return a list of FQPs to subdirectories in the given directory func (d *Dir) GetSubdirs() (map[string]string, error) { diff --git a/cmd/linuxdb.go b/cmd/linuxdb.go index 58892f5f3..fbea6b686 100644 --- a/cmd/linuxdb.go +++ b/cmd/linuxdb.go @@ -3,7 +3,6 @@ package cmd import ( "log" - "github.com/leaanthony/mewn" "gopkg.in/yaml.v3" ) @@ -79,11 +78,14 @@ func (l *LinuxDB) GetDistro(distro string) *Distribution { // NewLinuxDB creates a new LinuxDB instance from the bundled // linuxdb.yaml file. func NewLinuxDB() *LinuxDB { - data := mewn.Bytes("./linuxdb.yaml") + data, err := fs.LoadRelativeFile("./linuxdb.yaml") + if err != nil { + log.Fatal("Could not load linuxdb.yaml") + } result := LinuxDB{ Distributions: make(map[string]*Distribution), } - err := result.ImportData(data) + err = result.ImportData(data) if err != nil { log.Fatal(err) }