remove

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RemoveCmd = &cobra.Command{
	Use:     "remove",
	Aliases: []string{"delete"},
	Short:   "remove a package repository",
	Long: `

The "config remove" subcommand allows you to remove a package repository.
`,
	RunE: func(cmd *cobra.Command, args []string) error {
		cfg, err := config.Load()
		if err != nil {
			return err
		}

		if len(cfg.PkgRepos) == 1 {
			return errors.New("cannot remove only package repository")
		}

		opts := make([]string, 0, len(cfg.PkgRepos))
		for _, pkgRepo := range cfg.PkgRepos {
			opts = append(opts, pkgRepo.Name)
		}

		q := &survey.Select{
			Message: "Repository to remove",
			Options: opts,
		}

		var pkg string
		if err := survey.AskOne(q, &pkg, survey.WithValidator(survey.Required)); err != nil {
			return err
		}

		var remove *config.PkgRepo
		for idx, pkgRepo := range cfg.PkgRepos {
			if pkgRepo.Name == pkg {
				remove = pkgRepo
				cfg.PkgRepos = append(cfg.PkgRepos[:idx], cfg.PkgRepos[idx+1:]...)
				break
			}
		}

		if remove != nil {
			if err := os.RemoveAll(remove.Path()); err != nil {
				return err
			}
		}

		if err := cfg.Save(); err != nil {
			return err
		}

		color.HiGreen("Repository %q successfully removed", 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