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 { return cmd.Help() } cfg, err := config.Load() if err != nil { return err } if utils.RecipeDirFlag == "" { for _, pkgRepo := range cfg.PkgRepos { shouldRefresh, err := pkgRepo.ShouldRefreshRecipes(cfg.RefreshInterval) if err != nil { return err } if shouldRefresh || doRefresh { color.HiBlue("Refreshing package recipes for %q...", pkgRepo.Name) if err = pkgRepo.RefreshRecipes(); err != nil { color.Red("%v", err) } } } } pkgInfos := make([]*pkgparse.PkgInfo, 0) for _, pkgRepo := range cfg.PkgRepos { files, err := os.ReadDir(filepath.Join(pkgRepo.Path(), "pkgs")) if err != nil { return err } for _, file := range files { pkg := strings.Split(file.Name(), utils.PkgRecipeExt)[0] pkgInfo, err := pkgparse.ParsePkgInfo(pkgRepo.Path(), pkg) if err != nil { return err } pkgInfos = append(pkgInfos, pkgInfo) } } sort.Slice(pkgInfos, func(i, j int) bool { return pkgInfos[i].Title < pkgInfos[j].Title }) 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(cfg.PkgRepos, pkg, 0, 1, &wg, &ml) { return errors.New("failed to install pkg") } return nil }, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.