search

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SearchCmd = &cobra.Command{
	Use:   "search",
	Short: "search for a package",
	Long: `
The "search" subcommand starts an interactive window to find and display info about a package`,
	Example: `webman search`,
	RunE: func(cmd *cobra.Command, args []string) error {
		if len(args) != 0 {
			cmd.Help()
			return nil
		}
		utils.Init()
		files, err := os.ReadDir(filepath.Join(utils.WebmanRecipeDir, "pkgs"))
		if err != nil {
			return err
		}
		pkgInfos := make([]*pkgparse.PkgInfo, len(files))
		for i, file := range files {
			pkg := strings.Split(file.Name(), utils.PkgRecipeExt)[0]
			pkgInfo, err := pkgparse.ParsePkgInfo(pkg)
			if err != nil {
				return err
			}
			pkgInfos[i] = pkgInfo
		}
		idx, err := fuzzyfinder.Find(
			pkgInfos,
			func(i int) string {
				return pkgInfos[i].Title + " - " + pkgInfos[i].Tagline
			},
			fuzzyfinder.WithPreviewWindow(func(i, w, h int) string {
				if i == -1 {
					return ""
				}
				return wrapText(fmt.Sprintf("%s: %s\n\n%s:\n %s\n\n%s:\n%s",
					"📦 Title",
					pkgInfos[i].Title,
					"💾 Tagline",
					pkgInfos[i].Tagline,
					"📄 About",
					pkgInfos[i].About), w)

			}))
		if err != nil {
			color.HiBlack("No package selected.")
			return nil
		}
		pkg := pkgInfos[idx].Title
		prompt := &survey.Confirm{
			Message: "Would you like to install the latest version of " + color.CyanString(pkg) + "?",
		}
		shouldInstall := false
		if err := survey.AskOne(prompt, &shouldInstall); err != nil || !shouldInstall {
			color.HiBlack("No package selected.")
			return nil
		}
		var wg sync.WaitGroup
		ml := multiline.New(1, os.Stdout)
		wg.Add(1)
		if !add.InstallPkg(pkg, 0, 1, &wg, &ml) {
			return errors.New("failed to install pkg")
		}
		return nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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