-
Notifications
You must be signed in to change notification settings - Fork 117
/
delete.go
73 lines (59 loc) · 1.8 KB
/
delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package project
import (
"fmt"
"github.com/rilldata/rill/cli/pkg/cmdutil"
adminv1 "github.com/rilldata/rill/proto/gen/rill/admin/v1"
"github.com/spf13/cobra"
)
func DeleteCmd(ch *cmdutil.Helper) *cobra.Command {
var name, path string
var force bool
deleteCmd := &cobra.Command{
Use: "delete [<project-name>]",
Args: cobra.MaximumNArgs(1),
Short: "Delete the project",
RunE: func(cmd *cobra.Command, args []string) error {
client, err := ch.Client()
if err != nil {
return err
}
if len(args) > 0 {
name = args[0]
}
if !cmd.Flags().Changed("project") && len(args) == 0 && ch.Interactive {
name, err = ch.InferProjectName(cmd.Context(), ch.Org, path)
if err != nil {
return err
}
}
if name == "" {
return fmt.Errorf("please provide a valid project name. Run `rill project list` to see the available projects")
}
if !force {
ch.PrintfWarn("Warn: Deleting the project %q will remove all metadata associated with the project\n", name)
msg := fmt.Sprintf("Type %q to confirm deletion", name)
project, err := cmdutil.InputPrompt(msg, "")
if err != nil {
return err
}
if project != name {
return fmt.Errorf("Entered incorrect name : %q, expected value is %q", project, name)
}
}
_, err = client.DeleteProject(cmd.Context(), &adminv1.DeleteProjectRequest{
OrganizationName: ch.Org,
Name: name,
})
if err != nil {
return err
}
ch.PrintfSuccess("Deleted project: %v\n", name)
return nil
},
}
deleteCmd.Flags().SortFlags = false
deleteCmd.Flags().BoolVar(&force, "force", false, "Delete forcefully, skips the confirmation")
deleteCmd.Flags().StringVar(&name, "project", "", "Project Name")
deleteCmd.Flags().StringVar(&path, "path", ".", "Project directory")
return deleteCmd
}