import.go

 1package cmd
 2
 3import (
 4	"github.com/charmbracelet/soft-serve/server/store"
 5	"github.com/spf13/cobra"
 6)
 7
 8// importCommand is the command for creating a new repository.
 9func importCommand() *cobra.Command {
10	var private bool
11	var description string
12	var projectName string
13	var mirror bool
14	var hidden bool
15
16	cmd := &cobra.Command{
17		Use:               "import REPOSITORY REMOTE",
18		Short:             "Import a new repository from remote",
19		Args:              cobra.ExactArgs(2),
20		PersistentPreRunE: checkIfCollab,
21		RunE: func(cmd *cobra.Command, args []string) error {
22			ctx := cmd.Context()
23			be, _ := fromContext(cmd)
24			name := args[0]
25			remote := args[1]
26			if _, err := be.ImportRepository(ctx, name, remote, store.RepositoryOptions{
27				Private:     private,
28				Description: description,
29				ProjectName: projectName,
30				Mirror:      mirror,
31				Hidden:      hidden,
32			}); err != nil {
33				return err
34			}
35			return nil
36		},
37	}
38
39	cmd.Flags().BoolVarP(&mirror, "mirror", "m", false, "mirror the repository")
40	cmd.Flags().BoolVarP(&private, "private", "p", false, "make the repository private")
41	cmd.Flags().StringVarP(&description, "description", "d", "", "set the repository description")
42	cmd.Flags().StringVarP(&projectName, "name", "n", "", "set the project name")
43	cmd.Flags().BoolVarP(&hidden, "hidden", "H", false, "hide the repository from the UI")
44
45	return cmd
46}