Skip to content

Commit

Permalink
refactor: separate func to apply filters
Browse files Browse the repository at this point in the history
  • Loading branch information
5n7-sk committed Dec 15, 2020
1 parent 18e1170 commit e41dcac
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions cli/cli_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ func (c *CLI) sanityCheck(app vin.App) error {
return nil
}

func (c *CLI) applyFilters(v *vin.Vin, opt Options) (*vin.Vin, error) {
host, err := os.Hostname()
if err != nil {
return v, err
}
v = v.FilterByHost(host)

v = v.FilterByPriority(opt.Priority)
return v, nil
}

func (c *CLI) selectApps(v *vin.Vin) (*vin.Vin, error) {
repos := make([]string, 0)
prompt := &survey.MultiSelect{
Expand Down Expand Up @@ -146,13 +157,11 @@ func (c *CLI) Run(opt Options) error { //nolint:gocognit
}

if !opt.IgnoreFilter {
host, err := os.Hostname()
vin, err := c.applyFilters(v, opt)
if err != nil {
return err
}
v = v.FilterByHost(host)

v = v.FilterByPriority(opt.Priority)
v = vin
}

if opt.SelectApps {
Expand Down

0 comments on commit e41dcac

Please sign in to comment.