Skip to content

Commit 1e43f14

Browse files
committed
Add 'environment delete' subcommand
1 parent d88da0d commit 1e43f14

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright © 2019 cloud.ca Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Package delete implements the `environment delete` command
16+
package delete
17+
18+
import (
19+
"github.com/cloud-ca/cca/pkg/cli"
20+
"github.com/cloud-ca/cca/pkg/output"
21+
"github.com/cloud-ca/cca/pkg/util"
22+
"github.com/spf13/cobra"
23+
)
24+
25+
type flag struct {
26+
id string
27+
}
28+
29+
// NewCommand returns a new cobra.Command for environment delete
30+
func NewCommand(cli *cli.Wrapper) *cobra.Command {
31+
flg := &flag{}
32+
cmd := &cobra.Command{
33+
Args: cobra.NoArgs,
34+
Use: "delete",
35+
Short: "Delete a specific environment",
36+
Long: util.LongDescription(`
37+
Delete a specific environment. You will need a role with the Delete an existing environment
38+
permission to execute this operation.
39+
`),
40+
RunE: func(cmd *cobra.Command, args []string) error {
41+
deleted, err := cli.CcaClient.Environments.Delete(flg.id)
42+
if err != nil {
43+
return err
44+
}
45+
return cli.OutputBuilder.Build(func(formatter *output.Formatter) error {
46+
type R struct {
47+
Deleted bool `json:"deleted"`
48+
}
49+
return formatter.Format(&R{Deleted: deleted})
50+
})
51+
},
52+
}
53+
54+
cmd.Flags().StringVar(&flg.id, "id", "", "ID of environment to delete")
55+
56+
err := cmd.MarkFlagRequired("id")
57+
if err != nil {
58+
panic(err)
59+
}
60+
61+
return cmd
62+
}

cmd/cca/environment/environment.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package environment
1717

1818
import (
19+
"github.com/cloud-ca/cca/cmd/cca/environment/delete"
1920
"github.com/cloud-ca/cca/cmd/cca/environment/list"
2021
"github.com/cloud-ca/cca/pkg/cli"
2122
"github.com/cloud-ca/cca/pkg/util"
@@ -39,6 +40,7 @@ func NewCommand(cli *cli.Wrapper) *cobra.Command {
3940
`),
4041
}
4142

43+
cmd.AddCommand(delete.NewCommand(cli))
4244
cmd.AddCommand(list.NewCommand(cli))
4345

4446
return cmd

0 commit comments

Comments
 (0)