|
| 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 | +} |
0 commit comments