project delete: use project ref

This commit is contained in:
Simone Gotti 2019-04-02 11:06:45 +02:00
parent ed502276ba
commit 99a6c12f98
2 changed files with 7 additions and 14 deletions

View File

@ -17,9 +17,9 @@ package cmd
import ( import (
"context" "context"
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/services/gateway/api" "github.com/sorintlab/agola/internal/services/gateway/api"
"github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -34,8 +34,7 @@ var cmdProjectDelete = &cobra.Command{
} }
type projectDeleteOptions struct { type projectDeleteOptions struct {
name string projectRef string
organizationName string
} }
var projectDeleteOpts projectDeleteOptions var projectDeleteOpts projectDeleteOptions
@ -43,10 +42,9 @@ var projectDeleteOpts projectDeleteOptions
func init() { func init() {
flags := cmdProjectDelete.Flags() flags := cmdProjectDelete.Flags()
flags.StringVarP(&projectDeleteOpts.name, "name", "n", "", "project name") flags.StringVar(&projectDeleteOpts.projectRef, "project", "", "project id or full path")
flags.StringVar(&projectDeleteOpts.organizationName, "orgname", "", "organization name where the project should be deleted")
cmdProjectDelete.MarkFlagRequired("name") cmdProjectDelete.MarkFlagRequired("project")
cmdProject.AddCommand(cmdProjectDelete) cmdProject.AddCommand(cmdProjectDelete)
} }
@ -56,13 +54,7 @@ func projectDelete(cmd *cobra.Command, args []string) error {
log.Infof("deleting project") log.Infof("deleting project")
var err error if _, err := gwclient.DeleteProject(context.TODO(), projectDeleteOpts.projectRef); err != nil {
if projectDeleteOpts.organizationName != "" {
_, err = gwclient.DeleteOrgProject(context.TODO(), projectDeleteOpts.organizationName, projectDeleteOpts.name)
} else {
_, err = gwclient.DeleteCurrentUserProject(context.TODO(), projectDeleteOpts.name)
}
if err != nil {
return errors.Wrapf(err, "failed to delete project") return errors.Wrapf(err, "failed to delete project")
} }

View File

@ -205,7 +205,7 @@ func (s *CommandHandler) DeleteProject(ctx context.Context, projectRef string) e
var err error var err error
// check project existance // check project existance
project, err := s.readDB.GetProject(tx, projectRef) project, err = s.readDB.GetProject(tx, projectRef)
if err != nil { if err != nil {
return err return err
} }
@ -229,6 +229,7 @@ func (s *CommandHandler) DeleteProject(ctx context.Context, projectRef string) e
return err return err
} }
// TODO(sgotti) delete project secrets/variables
actions := []*wal.Action{ actions := []*wal.Action{
{ {
ActionType: wal.ActionTypeDelete, ActionType: wal.ActionTypeDelete,