Skip to content

Commit

Permalink
Fix Installed behavior
Browse files Browse the repository at this point in the history
plugin.installed() behavior was still kept as old implementations was.
So changed to use GetSources (it's considering glob) and add tilda
consideration

ref: #32
  • Loading branch information
babarot committed Mar 8, 2022
1 parent 588ae09 commit 16b4068
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions pkg/config/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os/exec"
"path/filepath"

"github.com/goccy/go-yaml"
"github.com/mattn/go-zglob"
)

Expand All @@ -21,15 +22,32 @@ type Plugin struct {
If string `yaml:"if"`
}

func (p *Plugin) UnmarshalYAML(b []byte) error {
type alias Plugin

tmp := struct {
*alias
Sources []string `yaml:"sources"`
}{
alias: (*alias)(p),
}

if err := yaml.Unmarshal(b, &tmp); err != nil {
return err
}

var sources []string
for _, source := range tmp.Sources {
sources = append(sources, expandTilda(os.ExpandEnv(source)))
}
p.Sources = sources

return nil
}

// Installed returns true ...
func (p Plugin) Installed(pkg Package) bool {
for _, source := range p.Sources {
matches := glob(filepath.Join(pkg.GetHome(), source))
if len(matches) == 0 {
return false
}
}
return true
return len(p.GetSources(pkg)) > 0
}

// Install is
Expand Down

0 comments on commit 16b4068

Please sign in to comment.