/
delete.go
55 lines (49 loc) · 1.14 KB
/
delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package organization
import (
"encoding/json"
"fmt"
"log"
"github.com/naiba/cloudssh/cmd/client/dao"
"github.com/naiba/cloudssh/internal/apiio"
"github.com/spf13/cobra"
)
// DeleteCmd ..
var DeleteCmd *cobra.Command
func init() {
DeleteCmd = &cobra.Command{
Use: "delete",
Short: "delete organization(s)",
}
DeleteCmd.Flags().UintSlice("id", []uint{}, "sever id list --id=\"1,3,4\"")
DeleteCmd.Run = delete
}
func delete(cmd *cobra.Command, args []string) {
id, _ := cmd.Flags().GetUintSlice("id")
var req apiio.DeleteOrganizationRequest
req.ID = id
if len(req.ID) == 0 {
log.Println("Please input server id list")
return
}
fmt.Printf("Please type 'y' to confirm delete %+v:", req.ID)
var confirm string
fmt.Scanf("%s", &confirm)
if confirm != "y" {
return
}
body, err := dao.API.Do("/organization/batch-delete", "POST", req)
if err != nil {
log.Println("API Request", err)
return
}
var resp apiio.Response
if err = json.Unmarshal(body, &resp); err != nil {
log.Println("API Request", string(body), err)
return
}
if !resp.Success {
log.Println("API Request", resp.Message)
return
}
log.Println(resp.Message)
}