check

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CheckCmd = &cobra.Command{
	Use:   "check [recipe-dir]",
	Short: "check a directory of recipes",
	Long: `
The "check" subcommand checks that all recipes in a directory are valid.`,
	Example: `webman check ~/repos/webman-pkgs/`,
	RunE: func(cmd *cobra.Command, args []string) error {
		if len(args) != 1 {
			return cmd.Help()
		}
		recipeDir, err := filepath.Abs(args[0])
		utils.WebmanRecipeDir = recipeDir
		if err != nil {
			return err
		}
		entries, err := os.ReadDir(filepath.Join(recipeDir, "pkgs"))
		if err != nil {
			return err
		} else {
			var wg sync.WaitGroup
			success := true
			wg.Add(len(entries))
			for _, recipe := range entries {
				recipe := recipe

				go func() {
					recipeName := recipe.Name()
					pkg := strings.ReplaceAll(recipeName, utils.PkgRecipeExt, "")
					err := CheckPkgConfig(pkg)
					if err != nil {
						var lintErr schema.ResultErrors
						if errors.As(err, &lintErr) {
							for _, le := range lintErr {
								color.Red("%s: %s", color.YellowString(recipeName), color.RedString("%s: %s", le.Field(), le.Description()))
							}
						} else {
							color.Red("%s: %s", color.YellowString(recipeName), color.RedString("%v", err))
						}
						success = false
					}
					wg.Done()
				}()
			}
			wg.Wait()
			if !success {
				return fmt.Errorf("Not all packages are valid!")
			}
			color.Green("All packages are valid!")

			groupsPath := filepath.Join(recipeDir, "groups")
			groups, err := os.ReadDir(groupsPath)
			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(filepath.Join(groupsPath, recipeName)); 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
		}
	},
}

CheckCmd represents the remove command

Functions

func CheckGroup added in v0.9.0

func CheckGroup(path string) error

func CheckPkgConfig

func CheckPkgConfig(pkg string) error

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL