add

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AddCmd = &cobra.Command{
	Use:   "add [group]",
	Short: "install a group of packages",
	Long: `

The "group add" subcommand installs a group of packages.
`,

	Run: func(cmd *cobra.Command, args []string) {
		utils.Init()
		if len(args) != 1 {
			color.Red("Expected a single package group name")
			cmd.Help()
			os.Exit(1)
		}
		if utils.RecipeDirFlag == "" {

			shouldRefresh, err := pkgparse.ShouldRefreshRecipes()
			if err != nil {
				panic(err)
			}
			if shouldRefresh || doRefresh {
				color.HiBlue("Refreshing package recipes...")
				if err = pkgparse.RefreshRecipes(); err != nil {
					fmt.Println(err)
				} else {
					color.HiBlue("%s%sRefreshed package recipes!",
						multiline.MoveUp, multiline.ClearLine)
				}
			}
		}
		group := args[0]
		groupConf := pkgparse.ParseGroupConfig(group)

		var pkgsToInstall []string
		if allFlag {
			pkgsToInstall = groupConf.Packages
		} else {
			pkgInfos, err := pkgparse.ParseMultiPkgInfo(groupConf.Packages)
			if err != nil {
				color.Red("failed to parse package info: %v", err)
			}
			infoLines := make([]string, len(pkgInfos))
			for i, pkgInfo := range pkgInfos {
				infoLines[i] = color.CyanString(pkgInfo.Title) + color.HiBlackString(" - ") + pkgInfo.Tagline
			}
			prompt := &survey.MultiSelect{
				Message:  "Select packages from group " + color.YellowString(group) + " to install:",
				Options:  infoLines,
				PageSize: 10,
			}
			var indices []int
			survey.AskOne(prompt, &indices)
			for _, val := range indices {
				pkgsToInstall = append(pkgsToInstall, groupConf.Packages[val])
			}
		}
		if len(pkgsToInstall) == 0 {
			color.HiBlack("No packages selected for installation.")
		} else {
			if !add.InstallAllPkgs(pkgsToInstall) {
				color.Magenta("Not all packages installed successfully")
				os.Exit(1)
			}
			color.Green("All %d selected packages from group %s are installed", len(pkgsToInstall), color.YellowString(group))
		}
	},
}

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