add

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AddCmd = &cobra.Command{
	Use:   "add",
	Short: "add a package repository",
	Long: `

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

		var repo PkgRepo
		qs := []*survey.Question{
			{
				Name: "name",
				Prompt: &survey.Input{
					Message: "Repository name",
				},
				Validate: survey.Required,
			},
			{
				Name: "type",
				Prompt: &survey.Select{
					Message: "Repository type",
					Options: []string{"gitea", "github"},
				},
				Validate: survey.Required,
			},
			{
				Name: "user",
				Prompt: &survey.Input{
					Message: "Git user name",
				},
				Validate: survey.Required,
			},
			{
				Name: "repo",
				Prompt: &survey.Input{
					Message: "Git repository name",
				},
				Validate: survey.Required,
			},
			{
				Name: "branch",
				Prompt: &survey.Input{
					Message: "Git branch name",
					Default: "main",
				},
			},
		}

		if err := survey.Ask(qs, &repo); err != nil {
			return err
		}

		if repo.Type == config.PkgRepoTypeGitea {
			q := &survey.Input{
				Message: "Gitea URL",
			}
			if err := survey.AskOne(q, &repo.GiteaURL, survey.WithValidator(survey.Required)); err != nil {
				return err
			}
		}

		p := config.PkgRepo(repo)

		ok, err := p.Validate()
		if err != nil {
			return err
		}
		if !ok {
			return fmt.Errorf("%q is an invalid package repository; no `pkgs` sub-directory", p.Name)
		}

		if err := p.RefreshRecipes(); err != nil {
			return err
		}

		cfg.PkgRepos = append(cfg.PkgRepos, &p)

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

		color.HiGreen("Repository %q successfully added", repo.Name)
		return nil
	},
}

Functions

This section is empty.

Types

type PkgRepo

type PkgRepo config.PkgRepo

PkgRepo overrides config.PkgRepo in order to implement WriteAnswer without polluting the config package with survey details

func (*PkgRepo) WriteAnswer

func (p *PkgRepo) WriteAnswer(field string, value any) error

Jump to

Keyboard shortcuts

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