1package cmd
2
3import (
4 "fmt"
5
6 "github.com/charmbracelet/soft-serve/pkg/backend"
7 "github.com/charmbracelet/soft-serve/pkg/config"
8 "github.com/charmbracelet/soft-serve/pkg/proto"
9 "github.com/spf13/cobra"
10)
11
12// createCommand is the command for creating a new repository.
13func createCommand() *cobra.Command {
14 var private bool
15 var description string
16 var projectName string
17 var hidden bool
18
19 cmd := &cobra.Command{
20 Use: "create REPOSITORY",
21 Short: "Create a new repository",
22 Args: cobra.ExactArgs(1),
23 PersistentPreRunE: checkIfCollab,
24 RunE: func(cmd *cobra.Command, args []string) error {
25 ctx := cmd.Context()
26 cfg := config.FromContext(ctx)
27 be := backend.FromContext(ctx)
28 user := proto.UserFromContext(ctx)
29 name := args[0]
30 r, err := be.CreateRepository(ctx, name, user, proto.RepositoryOptions{
31 Private: private,
32 Description: description,
33 ProjectName: projectName,
34 Hidden: hidden,
35 })
36 if err != nil {
37 return err //nolint:wrapcheck
38 }
39
40 cloneurl := fmt.Sprintf("%s/%s.git", cfg.SSH.PublicURL, r.Name())
41 cmd.PrintErrf("Created repository %s\n", r.Name())
42 cmd.Println(cloneurl)
43
44 return nil
45 },
46 }
47
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}