/
delete.go
44 lines (39 loc) · 968 Bytes
/
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
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/YusukeIwaki/appetize-cli/appetize"
"github.com/pkg/errors"
)
// deleteCmd represents the delete command
var deleteCmd = &cobra.Command{
Use: "delete",
Short: "Deleting apps",
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if viper.GetString("api_token") == "" {
return errors.New("no api token specified")
}
client := appetize.Client{
ApiToken: viper.GetString("api_token"),
}
for _, arg := range args {
options := appetize.DeleteOptions{
PublicKey: arg,
}
deleteResponse, err := client.DeleteApp(options)
if err != nil {
fmt.Printf("%s\tERROR:%s\n", arg, err.Error())
} else if deleteResponse.Body != "OK" {
fmt.Printf("%s\terror:%s\n", arg, deleteResponse.Body)
} else {
fmt.Printf("%s\tOK\n", arg)
}
}
return nil
},
}
func init() {
rootCmd.AddCommand(deleteCmd)
}