Skip to content

Commit

Permalink
feat(projects): add delete command
Browse files Browse the repository at this point in the history
  • Loading branch information
noetarbouriech committed Jul 11, 2023
1 parent 70b9e4a commit 63bd841
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
28 changes: 27 additions & 1 deletion cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"os"

"github.com/paastech-cloud/cli/internal/config"
"github.com/paastech-cloud/cli/pkg/project"
"github.com/paastech-cloud/cli/pkg/utils"
"github.com/spf13/cobra"
)
Expand All @@ -16,10 +18,34 @@ var deleteCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Println("Deleting this project from PaasTech")

userCfg, err := config.LoadAuthConfig()
if err != nil {
return err
}

projCfg, err := config.LoadProjectConfig()
if err != nil {
return err
}

// confirmation
stdin := bufio.NewReader(os.Stdin)
if utils.ConfirmationPrompt(stdin) {
// return project.DeleteProject(viper.GetString("server"), viper.GetString("jwt"), "todo")
var project project.Project
projCfg.UnmarshalKey("project", &project)

err := project.Delete(userCfg.GetString("server"), userCfg.GetString("jwt"))
if err != nil {
return err
}

os.Remove("paastech.yaml")
if err != nil {
return err
}

fmt.Println("Project deleted successfully")
return nil
}

return nil
Expand Down
15 changes: 4 additions & 11 deletions pkg/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ type projectCreationResponse struct {
}

type Project struct {
Id string `json:"id"`
Name string `json:"name"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Id string `json:"id" yaml:"id"`
Name string `json:"name" yaml:"name"`
CreatedAt time.Time `json:"createdAt" yaml:"createdat"`
UpdatedAt time.Time `json:"updatedAt" yaml:"updatedat"`
}

// Send a project creation request to the PaaSTech API and returns a Project object if successful
Expand Down Expand Up @@ -91,12 +91,5 @@ func (p *Project) Delete(baseURL string, accessToken string) error {
return err
}

// Parse JSON body
var project Project
err = json.NewDecoder(resp.Body).Decode(&project)
if err != nil {
return err
}

return nil
}

0 comments on commit 63bd841

Please sign in to comment.