From 85b8888f76ef1cada0ea1f6c52d62208c30c8a61 Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Tue, 1 Oct 2019 10:15:16 +0200 Subject: [PATCH] cmd: add project group delete command --- cmd/agola/cmd/projectdelete.go | 8 ++-- cmd/agola/cmd/projectgroupdelete.go | 64 +++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 cmd/agola/cmd/projectgroupdelete.go diff --git a/cmd/agola/cmd/projectdelete.go b/cmd/agola/cmd/projectdelete.go index 49915a3..0a572f1 100644 --- a/cmd/agola/cmd/projectdelete.go +++ b/cmd/agola/cmd/projectdelete.go @@ -34,7 +34,7 @@ var cmdProjectDelete = &cobra.Command{ } type projectDeleteOptions struct { - projectRef string + ref string } var projectDeleteOpts projectDeleteOptions @@ -42,9 +42,9 @@ var projectDeleteOpts projectDeleteOptions func init() { flags := cmdProjectDelete.Flags() - flags.StringVar(&projectDeleteOpts.projectRef, "project", "", "project id or full path") + flags.StringVar(&projectDeleteOpts.ref, "ref", "", "project path or id") - if err := cmdProjectDelete.MarkFlagRequired("project"); err != nil { + if err := cmdProjectDelete.MarkFlagRequired("ref"); err != nil { log.Fatal(err) } @@ -56,7 +56,7 @@ func projectDelete(cmd *cobra.Command, args []string) error { log.Infof("deleting project") - if _, err := gwclient.DeleteProject(context.TODO(), projectDeleteOpts.projectRef); err != nil { + if _, err := gwclient.DeleteProject(context.TODO(), projectDeleteOpts.ref); err != nil { return errors.Errorf("failed to delete project: %w", err) } diff --git a/cmd/agola/cmd/projectgroupdelete.go b/cmd/agola/cmd/projectgroupdelete.go new file mode 100644 index 0000000..fddb41c --- /dev/null +++ b/cmd/agola/cmd/projectgroupdelete.go @@ -0,0 +1,64 @@ +// Copyright 2019 Sorint.lab +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied +// See the License for the specific language governing permissions and +// limitations under the License. + +package cmd + +import ( + "context" + + gwclient "agola.io/agola/services/gateway/client" + + "github.com/spf13/cobra" + errors "golang.org/x/xerrors" +) + +var cmdProjectGroupDelete = &cobra.Command{ + Use: "delete", + Short: "delete a project group", + Run: func(cmd *cobra.Command, args []string) { + if err := projectGroupDelete(cmd, args); err != nil { + log.Fatalf("err: %v", err) + } + }, +} + +type projectGroupDeleteOptions struct { + ref string +} + +var projectGroupDeleteOpts projectGroupDeleteOptions + +func init() { + flags := cmdProjectGroupDelete.Flags() + + flags.StringVarP(&projectGroupDeleteOpts.ref, "ref", "", "", "current project group path or id") + + if err := cmdProjectGroupDelete.MarkFlagRequired("ref"); err != nil { + log.Fatal(err) + } + + cmdProjectGroup.AddCommand(cmdProjectGroupDelete) +} + +func projectGroupDelete(cmd *cobra.Command, args []string) error { + gwclient := gwclient.NewClient(gatewayURL, token) + + log.Infof("deleting project group") + + if _, err := gwclient.DeleteProjectGroup(context.TODO(), projectGroupDeleteOpts.ref); err != nil { + return errors.Errorf("failed to delete project group: %w", err) + } + + return nil +}