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