-
Notifications
You must be signed in to change notification settings - Fork 5
/
get.go
79 lines (75 loc) · 2.2 KB
/
get.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package cli
import (
"fmt"
"os"
"github.com/sirupsen/logrus"
"github.com/containerum/chkit/pkg/cli/configmap"
"github.com/containerum/chkit/pkg/cli/containerumapi"
"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/cli/solution"
"github.com/containerum/chkit/pkg/cli/user"
"github.com/containerum/chkit/pkg/configuration"
"github.com/containerum/chkit/pkg/context"
"github.com/containerum/chkit/pkg/util/angel"
"github.com/spf13/cobra"
)
func Get(ctx *context.Context) *cobra.Command {
command := &cobra.Command{
Use: "get",
Short: "Get resource data",
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(
clideployment.Get(ctx),
clinamespace.Get(ctx),
clinamespace.GetAccess(ctx),
cliserv.Get(ctx),
clipod.Get(ctx),
clingress.Get(ctx),
cliuser.Get(ctx),
clisolution.Get(ctx),
containerumapi.Get(ctx),
cliconfigmap.Get(ctx),
&cobra.Command{
Use: "default-namespace",
Short: "print default",
Aliases: []string{"default-ns", "def-ns"},
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("%s\n", ctx.Namespace)
},
},
)
command.PersistentFlags().
StringP("namespace", "n", ctx.Namespace, "")
return command
}