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: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NestedRecipe = Check{
	Name: "Nested Recipes",
	Func: func(cfg *config.Config, fix bool) error {
		_, pkgsErr := os.Stat(filepath.Join(utils.WebmanRecipeDir, "pkgs"))
		_, groupsErr := os.Stat(filepath.Join(utils.WebmanRecipeDir, "groups"))
		if errors.Is(pkgsErr, fs.ErrNotExist) && errors.Is(groupsErr, fs.ErrNotExist) {
			color.HiGreen("no un-nested recipes detected")
			return nil
		}

		if !fix {
			color.HiRed("detected un-nested recipes, please clean up %q", utils.WebmanRecipeDir)
			return nil
		}

		remove := []string{".github", "groups", "pkgs", ".mega-linter.yml", ".pre-commit-config.yaml", "LICENSE", "README.md", "full-bintest.sh", "refresh.yaml"}
		for _, r := range remove {
			if err := os.RemoveAll(filepath.Join(utils.WebmanRecipeDir, r)); err != nil {
				color.HiRed("could not remove %q: %v", r, err)
			}
		}

		color.HiGreen("successfully cleaned un-nested recipes")
		return nil
	},
}

NestedRecipe v0.8.0 -> v0.9.0 introduced configurable repos, which moved the recipes dir one level deeper

View Source
var WindowsSymlink = Check{
	Name: "Windows Symlink",
	Func: func(cfg *config.Config, fix bool) error {
		if utils.GOOS != "windows" {
			color.HiGreen("current OS isn't windows; skipping")
			return nil
		}

		installed, err := os.ReadDir(utils.WebmanPkgDir)
		if err != nil {
			return err
		}

		for _, i := range installed {
			pkgConfig, err := pkgparse.ParsePkgConfigLocal(cfg.PkgRepos, i.Name())
			if err != nil {
				return err
			}

			binPaths, err := pkgConfig.GetMyBinPaths()
			if err != nil {
				return err
			}
			renames, err := pkgConfig.GetRenames()
			if err != nil {
				return err
			}
			using, err := pkgparse.CheckUsing(i.Name())
			if err != nil {
				return err
			}
			parts := strings.Split(*using, "-")
			ver := parts[len(parts)-1]

			_, err = os.Lstat(filepath.Join(utils.WebmanBinDir, i.Name()+".exe"))
			if err == nil {
				continue
			}
			if err != nil {
				if !errors.Is(err, fs.ErrNotExist) {
					color.HiRed("could not lstat %q: %v", i.Name(), err)
					continue
				}
			}

			if !fix {
				color.HiRed("no symlink(s) found for %q", i.Name())
				continue
			}

			color.HiGreen("creating symlink(s) for %s", i.Name())
			if _, err := link.CreateLinks(i.Name(), ver, binPaths, renames); err != nil {
				color.HiRed("could not create symlink(s) for %q: %v", i.Name(), err)
			}
		}

		bats, err := filepath.Glob(filepath.Join(utils.WebmanBinDir, "*.bat"))
		if err != nil {
			return err
		}

		if len(bats) == 0 {
			color.HiGreen("no batch files found")
			return nil
		}

		if !fix {
			color.HiRed("found %d batch file(s)", len(bats))
			return nil
		}

		color.HiGreen("removing batch file(s)")
		for _, bat := range bats {
			if err := os.Remove(bat); err != nil {
				color.HiRed("could not remove batch file %q: %v", bat, err)
			}
		}

		return nil
	},
}

Windows switched from batch files to symlinks

Functions

This section is empty.

Types

type Check

type Check struct {
	Name string
	Func func(cfg *config.Config, fix bool) error
}

Jump to

Keyboard shortcuts

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