File tree 4 files changed +56
-9
lines changed
4 files changed +56
-9
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,9 @@ package cmd
2
2
3
3
import (
4
4
"fmt"
5
+ "os"
5
6
7
+ "github.com/arunvelsriram/kube-tmuxp/pkg/kubetmuxp"
6
8
"github.com/spf13/cobra"
7
9
)
8
10
@@ -11,7 +13,13 @@ var generateCmd = &cobra.Command{
11
13
Aliases : []string {"gen" },
12
14
Short : "Generates tmuxp configs for various Kubernetes contexts" ,
13
15
Run : func (cmd * cobra.Command , args []string ) {
14
- fmt .Println ("Generate" )
16
+ kubetmuxpCfg , err := kubetmuxp .NewConfig (cfgFile )
17
+ if err != nil {
18
+ fmt .Println (err )
19
+ os .Exit (1 )
20
+ }
21
+
22
+ fmt .Printf ("%+v\n " , kubetmuxpCfg )
15
23
},
16
24
}
17
25
Original file line number Diff line number Diff line change 1
- - project : gcp-project-id
2
- clusters :
3
- - name : gke-cluster-name
4
- zone : zone # for zonal GKE clusters
5
- region : region # for regional GKE clusters
6
- context : name-to-be-used-for-this-context
7
- extra_envs :
8
- ENV_VARIABLE : value
1
+ projects :
2
+ - name : gcp-project-id
3
+ clusters :
4
+ - name : gke-cluster-name
5
+ zone : zone # for zonal GKE clusters
6
+ region : region # for regional GKE clusters
7
+ context : name-to-be-used-for-this-context
8
+ envs :
9
+ ENV_VARIABLE : value
9
10
Original file line number Diff line number Diff line change @@ -8,4 +8,5 @@ require (
8
8
github.com/spf13/cobra v0.0.3
9
9
github.com/spf13/viper v1.2.1
10
10
github.com/stretchr/testify v1.2.2 // indirect
11
+ gopkg.in/yaml.v2 v2.2.1
11
12
)
Original file line number Diff line number Diff line change
1
+ package kubetmuxp
2
+
3
+ import (
4
+ "io/ioutil"
5
+
6
+ yaml "gopkg.in/yaml.v2"
7
+ )
8
+
9
+ // Config represents kube-tmuxp config
10
+ type Config struct {
11
+ Projects []struct {
12
+ Name string `yaml:"name"`
13
+ Clusters []struct {
14
+ Name string `yaml:"name"`
15
+ Zone string `yaml:"zone"`
16
+ Region string `yaml:"region"`
17
+ Context string `yaml:"context"`
18
+ Envs map [string ]string `yaml:"envs"`
19
+ }
20
+ }
21
+ }
22
+
23
+ // NewConfig constructs kube-tmuxp config from given file
24
+ func NewConfig (cfgFile string ) (Config , error ) {
25
+ var config Config
26
+ data , err := ioutil .ReadFile (cfgFile )
27
+ if err != nil {
28
+ return config , err
29
+ }
30
+
31
+ err = yaml .Unmarshal (data , & config )
32
+ if err != nil {
33
+ return config , err
34
+ }
35
+
36
+ return config , nil
37
+ }
You can’t perform that action at this time.
0 commit comments