1package cmd
2
3import (
4 "github.com/charmbracelet/soft-serve/server/store"
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 var hidden bool
14
15 cmd := &cobra.Command{
16 Use: "create REPOSITORY",
17 Short: "Create a new repository",
18 Args: cobra.ExactArgs(1),
19 PersistentPreRunE: checkIfCollab,
20 RunE: func(cmd *cobra.Command, args []string) error {
21 ctx := cmd.Context()
22 be, _ := fromContext(cmd)
23 name := args[0]
24 if _, err := be.CreateRepository(ctx, name, store.RepositoryOptions{
25 Private: private,
26 Description: description,
27 ProjectName: projectName,
28 Hidden: hidden,
29 }); err != nil {
30 return err
31 }
32 return nil
33 },
34 }
35
36 cmd.Flags().BoolVarP(&private, "private", "p", false, "make the repository private")
37 cmd.Flags().StringVarP(&description, "description", "d", "", "set the repository description")
38 cmd.Flags().StringVarP(&projectName, "name", "n", "", "set the project name")
39 cmd.Flags().BoolVarP(&hidden, "hidden", "H", false, "hide the repository from the UI")
40
41 return cmd
42}