1package cmd
2
3import (
4 "github.com/charmbracelet/soft-serve/server/backend"
5 "github.com/spf13/cobra"
6)
7
8// createCommand is the command for creating a new repository.
9func createCommand() *cobra.Command {
10 var private bool
11 var description string
12 var projectName string
13
14 cmd := &cobra.Command{
15 Use: "create REPOSITORY",
16 Short: "Create a new repository",
17 Args: cobra.ExactArgs(1),
18 PersistentPreRunE: checkIfAdmin,
19 RunE: func(cmd *cobra.Command, args []string) error {
20 cfg, _ := fromContext(cmd)
21 name := args[0]
22 if _, err := cfg.Backend.CreateRepository(name, backend.RepositoryOptions{
23 Private: private,
24 Description: description,
25 ProjectName: projectName,
26 }); err != nil {
27 return err
28 }
29 return nil
30 },
31 }
32
33 cmd.Flags().BoolVarP(&private, "private", "p", false, "make the repository private")
34 cmd.Flags().StringVarP(&description, "description", "d", "", "set the repository description")
35 cmd.Flags().StringVarP(&projectName, "name", "n", "", "set the project name")
36
37 return cmd
38}