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// createCommand is the command for creating a new repository.
10func createCommand() *cobra.Command {
11	var private bool
12	var description string
13	var projectName string
14	var hidden bool
15
16	cmd := &cobra.Command{
17		Use:               "create REPOSITORY",
18		Short:             "Create a new repository",
19		Args:              cobra.ExactArgs(1),
20		PersistentPreRunE: checkIfCollab,
21		RunE: func(cmd *cobra.Command, args []string) error {
22			ctx := cmd.Context()
23			be := backend.FromContext(ctx)
24			user := proto.UserFromContext(ctx)
25			name := args[0]
26			if _, err := be.CreateRepository(ctx, name, user, proto.RepositoryOptions{
27				Private:     private,
28				Description: description,
29				ProjectName: projectName,
30				Hidden:      hidden,
31			}); err != nil {
32				return err
33			}
34			return nil
35		},
36	}
37
38	cmd.Flags().BoolVarP(&private, "private", "p", false, "make the repository private")
39	cmd.Flags().StringVarP(&description, "description", "d", "", "set the repository description")
40	cmd.Flags().StringVarP(&projectName, "name", "n", "", "set the project name")
41	cmd.Flags().BoolVarP(&hidden, "hidden", "H", false, "hide the repository from the UI")
42
43	return cmd
44}