Merge pull request #132 from sgotti/cmd_projectgroup_delete
cmd: add project group delete command
This commit is contained in:
commit
eec25e6069
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue