|
|
@@ -4,10 +4,13 @@ import (
|
|
|
"context"
|
|
|
"fmt"
|
|
|
"os"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
"text/tabwriter"
|
|
|
|
|
|
"github.com/fatih/color"
|
|
|
"github.com/porter-dev/porter/cli/cmd/api"
|
|
|
+ "github.com/porter-dev/porter/cli/cmd/utils"
|
|
|
"github.com/spf13/cobra"
|
|
|
)
|
|
|
|
|
|
@@ -31,6 +34,19 @@ var createProjectCmd = &cobra.Command{
|
|
|
},
|
|
|
}
|
|
|
|
|
|
+var deleteProjectCmd = &cobra.Command{
|
|
|
+ Use: "delete [id]",
|
|
|
+ Args: cobra.ExactArgs(1),
|
|
|
+ Short: "Deletes the project with the given id",
|
|
|
+ Run: func(cmd *cobra.Command, args []string) {
|
|
|
+ err := checkLoginAndRun(args, deleteProject)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ os.Exit(1)
|
|
|
+ }
|
|
|
+ },
|
|
|
+}
|
|
|
+
|
|
|
var listProjectCmd = &cobra.Command{
|
|
|
Use: "list",
|
|
|
Short: "Lists the projects for the logged in user",
|
|
|
@@ -58,8 +74,6 @@ var listProjectClustersCmd = &cobra.Command{
|
|
|
func init() {
|
|
|
rootCmd.AddCommand(projectCmd)
|
|
|
|
|
|
- projectCmd.AddCommand(createProjectCmd)
|
|
|
-
|
|
|
projectCmd.PersistentFlags().StringVar(
|
|
|
&host,
|
|
|
"host",
|
|
|
@@ -67,6 +81,10 @@ func init() {
|
|
|
"host url of Porter instance",
|
|
|
)
|
|
|
|
|
|
+ projectCmd.AddCommand(createProjectCmd)
|
|
|
+
|
|
|
+ projectCmd.AddCommand(deleteProjectCmd)
|
|
|
+
|
|
|
projectCmd.AddCommand(listProjectCmd)
|
|
|
|
|
|
projectCmd.AddCommand(listProjectClustersCmd)
|
|
|
@@ -113,6 +131,38 @@ func listProjects(user *api.AuthCheckResponse, client *api.Client, args []string
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
+func deleteProject(_ *api.AuthCheckResponse, client *api.Client, args []string) error {
|
|
|
+ userResp, err := utils.PromptPlaintext(
|
|
|
+ fmt.Sprintf(
|
|
|
+ `Are you sure you'd like to delete the project with id %s? %s `,
|
|
|
+ args[0],
|
|
|
+ color.New(color.FgCyan).Sprintf("[y/n]"),
|
|
|
+ ),
|
|
|
+ )
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ if userResp := strings.ToLower(userResp); userResp == "y" || userResp == "yes" {
|
|
|
+ id, err := strconv.ParseUint(args[0], 10, 64)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ resp, err := client.DeleteProject(context.Background(), uint(id))
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ color.New(color.FgGreen).Printf("Deleted project with name %s and id %d\n", resp.Name, resp.ID)
|
|
|
+ }
|
|
|
+
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
func listProjectClusters(user *api.AuthCheckResponse, client *api.Client, args []string) error {
|
|
|
clusters, err := client.ListProjectClusters(context.Background(), getProjectID())
|
|
|
|