1package repo
2
3import (
4 "github.com/charmbracelet/soft-serve/cmd"
5 "github.com/charmbracelet/soft-serve/pkg/access"
6 "github.com/charmbracelet/soft-serve/pkg/backend"
7 "github.com/charmbracelet/soft-serve/pkg/proto"
8 "github.com/spf13/cobra"
9)
10
11func renameCommand() *cobra.Command {
12 cmd := &cobra.Command{
13 Use: "rename REPOSITORY NEW_NAME",
14 Aliases: []string{"mv", "move"},
15 Short: "Rename an existing repository",
16 Args: cobra.ExactArgs(2),
17 RunE: func(co *cobra.Command, args []string) error {
18 ctx := co.Context()
19 be := backend.FromContext(ctx)
20 oldName := args[0]
21 newName := args[1]
22
23 if !cmd.CheckUserHasAccess(co, oldName, access.ReadWriteAccess) {
24 return proto.ErrUnauthorized
25 }
26
27 return be.RenameRepository(ctx, oldName, newName)
28 },
29 }
30
31 return cmd
32}