-
Notifications
You must be signed in to change notification settings - Fork 1
/
cmd.go
57 lines (48 loc) · 1010 Bytes
/
cmd.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
package main
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
var (
filePath string
rootCmd = &cobra.Command{Use: "kbf"}
cmdPwd = &cobra.Command{
Use: "port-forward",
Short: "port-forward to k8s services using yml",
Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
f, err := loadFromFile(filePath)
if err != nil {
showErrorAndExit(cmd, err)
}
err = portForwarding(f)
if err != nil {
showErrorAndExit(cmd, err)
}
},
}
)
func Execute() error {
return rootCmd.Execute()
}
func init() {
cobra.OnInitialize(initConfig)
cmdPwd.Flags().StringVarP(&filePath, "file", "f", "forward.yml", "forward file path")
rootCmd.AddCommand(cmdPwd)
}
func showErrorAndExit(cmd *cobra.Command, err error) {
fmt.Println("Error: " + err.Error())
fmt.Println(cmd.UsageString())
os.Exit(1)
}
func initConfig() {
fmt.Println(`
_ ______ _____
| |/ | __ )| ___|
| ' /| _ \| |_
| . \| |_) | _|
|_|\_|____/|_|
Kubernetes yaml port-forward ;)
`)
}