-
Notifications
You must be signed in to change notification settings - Fork 5
/
delete.go
65 lines (61 loc) · 1.79 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
56
57
58
59
60
61
62
63
64
65
package cli
import (
"fmt"
"os"
"github.com/containerum/chkit/pkg/cli/configmap"
"github.com/containerum/chkit/pkg/cli/deployment"
"github.com/containerum/chkit/pkg/cli/ingress"
"github.com/containerum/chkit/pkg/cli/namespace"
"github.com/containerum/chkit/pkg/cli/pod"
"github.com/containerum/chkit/pkg/cli/prerun"
"github.com/containerum/chkit/pkg/cli/service"
"github.com/containerum/chkit/pkg/configuration"
"github.com/containerum/chkit/pkg/context"
"github.com/containerum/chkit/pkg/util/angel"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
func Delete(ctx *context.Context) *cobra.Command {
command := &cobra.Command{
Use: "delete",
Short: "Delete resource",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
if err := prerun.PreRun(ctx); err != nil {
angel.Angel(ctx, err)
os.Exit(1)
}
if cmd.Flags().Changed("namespace") {
ctx.Namespace, _ = cmd.Flags().GetString("namespace")
}
},
Run: func(command *cobra.Command, args []string) {
command.Help()
},
PersistentPostRun: func(command *cobra.Command, args []string) {
if ctx.Changed {
if err := configuration.SyncConfig(ctx); err != nil {
logrus.WithError(err).Errorf("unable to save config")
fmt.Printf("Unable to save config: %v\n", err)
return
}
}
if err := configuration.SaveTokens(ctx, ctx.Client.Tokens); err != nil {
logrus.WithError(err).Errorf("unable to save tokens")
fmt.Printf("Unable to save tokens: %v\n", err)
return
}
},
}
command.AddCommand(
clinamespace.Delete(ctx),
clinamespace.DeleteAccess(ctx),
cliserv.Delete(ctx),
clideployment.Delete(ctx),
clipod.Delete(ctx),
clingress.Delete(ctx),
cliconfigmap.Delete(ctx),
)
command.PersistentFlags().
StringP("namespace", "n", ctx.Namespace, "")
return command
}