-
Notifications
You must be signed in to change notification settings - Fork 5
/
replace.go
59 lines (54 loc) · 1.55 KB
/
replace.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
package cli
import (
"fmt"
"os"
"github.com/containerum/chkit/pkg/cli/deployment"
"github.com/containerum/chkit/pkg/cli/ingress"
"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 Replace(ctx *context.Context) *cobra.Command {
command := &cobra.Command{
Use: "replace",
Short: "Replace deployment or service",
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(cmd *cobra.Command, args []string) {
cmd.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.PersistentFlags().
StringP("namespace", "n", ctx.Namespace, "")
command.AddCommand(
clideployment.Replace(ctx),
cliserv.Replace(ctx),
clingress.Replace(ctx),
)
return command
}