1package cmd
2
3import "github.com/spf13/cobra"
4
5// createCommand is the command for creating a new repository.
6func createCommand() *cobra.Command {
7 var private bool
8 var description string
9 cmd := &cobra.Command{
10 Use: "create REPOSITORY",
11 Short: "Create a new repository",
12 Args: cobra.ExactArgs(1),
13 PersistentPreRunE: checkIfAdmin,
14 RunE: func(cmd *cobra.Command, args []string) error {
15 cfg, _ := fromContext(cmd)
16 name := args[0]
17 if _, err := cfg.Backend.CreateRepository(name, private); err != nil {
18 return err
19 }
20 return nil
21 },
22 }
23 cmd.Flags().BoolVarP(&private, "private", "p", false, "make the repository private")
24 cmd.Flags().StringVarP(&description, "description", "d", "", "set the repository description")
25 return cmd
26}