1
0
Fork 0
mirror of https://github.com/Luzifer/update-gotools.git synced 2024-12-22 12:51:20 +00:00

Add homdir expansion for paths

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2018-04-06 11:39:03 +02:00
parent b70c30eee7
commit 9da6796158
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
2 changed files with 28 additions and 9 deletions

10
main.go
View file

@ -2,12 +2,9 @@ package main
import (
"fmt"
"io/ioutil"
"os"
"runtime"
yaml "gopkg.in/yaml.v2"
"github.com/Luzifer/rconfig"
homedir "github.com/mitchellh/go-homedir"
log "github.com/sirupsen/logrus"
@ -55,12 +52,7 @@ func main() {
log.WithError(err).Fatal("Unable to create default config")
}
cfgFileRaw, err := ioutil.ReadFile(cfg.Config)
if err != nil {
log.WithError(err).Fatal("Unable to read config")
}
if err := yaml.Unmarshal(cfgFileRaw, cfgFile); err != nil {
if err := cfgFile.LoadFromPath(cfg.Config); err != nil {
log.WithError(err).Fatal("Unable to parse config file")
}

View file

@ -3,6 +3,11 @@ package main
import (
"io/ioutil"
"net/http"
"os"
homedir "github.com/mitchellh/go-homedir"
yaml "gopkg.in/yaml.v2"
)
type pkgCfg struct {
@ -20,6 +25,28 @@ type configFile struct {
PostCommands [][]string `yaml:"post_commands"`
}
func (c *configFile) LoadFromPath(filepath string) error {
r, err := os.Open(filepath)
if err != nil {
return err
}
defer r.Close()
if err := yaml.NewDecoder(r).Decode(cfgFile); err != nil {
return err
}
if c.Cwd, err = homedir.Expand(c.Cwd); err != nil {
return err
}
if c.GoPath, err = homedir.Expand(c.GoPath); err != nil {
return err
}
return nil
}
func (p *pkgCfg) Version() (string, error) {
if p.Ver != "" {
return p.Ver, nil