rename.go

 1package cmd
 2
 3import "github.com/spf13/cobra"
 4
 5func renameCommand() *cobra.Command {
 6	cmd := &cobra.Command{
 7		Use:               "rename REPOSITORY NEW_NAME",
 8		Aliases:           []string{"mv", "move"},
 9		Short:             "Rename an existing repository",
10		Args:              cobra.ExactArgs(2),
11		PersistentPreRunE: checkIfCollab,
12		RunE: func(cmd *cobra.Command, args []string) error {
13			ctx := cmd.Context()
14			be, _ := fromContext(cmd)
15			oldName := args[0]
16			newName := args[1]
17			if err := be.RenameRepository(ctx, oldName, newName); err != nil {
18				return err
19			}
20			return nil
21		},
22	}
23
24	return cmd
25}