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 name := args[0]
25 if _, err := be.CreateRepository(ctx, name, proto.RepositoryOptions{
26 Private: private,
27 Description: description,
28 ProjectName: projectName,
29 Hidden: hidden,
30 }); err != nil {
31 return err
32 }
33 return nil
34 },
35 }
36
37 cmd.Flags().BoolVarP(&private, "private", "p", false, "make the repository private")
38 cmd.Flags().StringVarP(&description, "description", "d", "", "set the repository description")
39 cmd.Flags().StringVarP(&projectName, "name", "n", "", "set the project name")
40 cmd.Flags().BoolVarP(&hidden, "hidden", "H", false, "hide the repository from the UI")
41
42 return cmd
43}