Skip to content

Commit

Permalink
add group checking to dev check command
Browse files Browse the repository at this point in the history
  • Loading branch information
candrewlee14 committed Sep 2, 2022
1 parent 650f930 commit 610c1ca
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions cmd/dev/check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
"sync"

"github.com/candrewlee14/webman/pkgparse"
"github.com/candrewlee14/webman/schema"
"github.com/candrewlee14/webman/utils"

Expand Down Expand Up @@ -64,11 +65,49 @@ The "check" subcommand checks that all recipes in a directory are valid.`,
return fmt.Errorf("Not all packages are valid!")
}
color.Green("All packages are valid!")

groups, err := os.ReadDir(filepath.Join(recipeDir, "groups"))
if err != nil {
return err
}
var wg2 sync.WaitGroup
success = true
wg2.Add(len(groups))
for _, groupEntry := range groups {
groupEntry := groupEntry
go func() {
recipeName := groupEntry.Name()
group := strings.ReplaceAll(recipeName, utils.GroupRecipeExt, "")
if err := CheckGroup(group); err != nil {
color.Red("%s: %s", color.MagentaString(group), color.RedString("%v", err))
success = false
}
wg2.Done()
}()
}
wg2.Wait()
if !success {
return fmt.Errorf("Not all groups are valid!")
}
color.Green("All groups are valid!")
return nil
}
},
}

func CheckGroup(group string) error {
groupConf := pkgparse.ParseGroupConfig(group)
if groupConf == nil {
return fmt.Errorf("no group file found for %s", group)
}
for _, pkg := range groupConf.Packages {
if err := CheckPkgConfig(pkg); err != nil {
return err
}
}
return nil
}

func CheckPkgConfig(pkg string) error {
pkgConfPath := filepath.Join(utils.WebmanRecipeDir, "pkgs", pkg+utils.PkgRecipeExt)
fi, err := os.Open(pkgConfPath)
Expand Down

0 comments on commit 610c1ca

Please sign in to comment.