Skip to content

Commit a38a3d7

Browse files
author
Marko Mikulicic
authored
Merge pull request #217 from bitnami-labs/view
Fix config view cmd
2 parents 658bf9c + 944e66a commit a38a3d7

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

cmd/config.go

+15-11
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,42 @@ import (
2020
"fmt"
2121
"io/ioutil"
2222
"os"
23+
"path/filepath"
2324

2425
"github.com/Sirupsen/logrus"
2526
"github.com/bitnami-labs/kubewatch/config"
2627
"github.com/bitnami-labs/kubewatch/pkg/client"
2728
"github.com/spf13/cobra"
2829
)
2930

31+
const kubewatchConfigFile = ".kubewatch.yaml"
32+
3033
// configCmd represents the config command
3134
var configCmd = &cobra.Command{
3235
Use: "config",
3336
Short: "modify kubewatch configuration",
3437
Long: `
35-
config command allows configuration of .kubewatch.yaml for running kubewatch`,
38+
config command allows configuration of ~/.kubewatch.yaml for running kubewatch`,
3639
Run: func(cmd *cobra.Command, args []string) {
3740
cmd.Help()
3841
},
3942
}
4043

4144
var configAddCmd = &cobra.Command{
4245
Use: "add",
43-
Short: "add webhook config to .kubewatch.yaml",
46+
Short: "add webhook config to ~/.kubewatch.yaml",
4447
Long: `
45-
Adds webhook config to .kubewatch.yaml`,
48+
Adds webhook config to ~/.kubewatch.yaml`,
4649
Run: func(cmd *cobra.Command, args []string) {
4750
cmd.Help()
4851
},
4952
}
5053

5154
var configTestCmd = &cobra.Command{
5255
Use: "test",
53-
Short: "test handler config present in .kubewatch.yaml",
56+
Short: "test handler config present in ~/.kubewatch.yaml",
5457
Long: `
55-
Tests handler configs present in .kubewatch.yaml by sending test messages`,
58+
Tests handler configs present in ~/.kubewatch.yaml by sending test messages`,
5659
Run: func(cmd *cobra.Command, args []string) {
5760
fmt.Println("Testing Handler configs from .kubewatch.yaml")
5861
conf, err := config.New()
@@ -66,16 +69,17 @@ Tests handler configs present in .kubewatch.yaml by sending test messages`,
6669

6770
var configViewCmd = &cobra.Command{
6871
Use: "view",
69-
Short: "view .kubewatch.yaml",
72+
Short: "view ~/.kubewatch.yaml",
7073
Long: `
71-
Display the contents of the contents of .kubewatch.yaml`,
74+
Display the contents of the contents of ~/.kubewatch.yaml`,
7275
Run: func(cmd *cobra.Command, args []string) {
73-
fmt.Println("Contents of .kubewatch.yaml")
74-
configFile, err := ioutil.ReadFile(os.Getenv("HOME") + "/" + ".kubewatch.yaml")
76+
fmt.Fprintln(os.Stderr, "Contents of ~/.kubewatch.yaml")
77+
configFile, err := ioutil.ReadFile(filepath.Join(os.Getenv("HOME"), kubewatchConfigFile))
7578
if err != nil {
76-
fmt.Printf("yamlFile.Get err #%v ", err)
79+
fmt.Fprintf(os.Stderr, "%v\n", err)
80+
os.Exit(1)
7781
}
78-
fmt.Println(string(configFile))
82+
fmt.Print(string(configFile))
7983
},
8084
}
8185

cmd/root.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ var RootCmd = &cobra.Command{
3636
Long: `
3737
Kubewath: A watcher for Kubernetes
3838
39-
kubewatch is a Kubernetes watcher that could publishes notification
40-
to Slack/hipchat/mattermost/flock channels. It watches the cluster
39+
kubewatch is a Kubernetes watcher that could publishes notification
40+
to Slack/hipchat/mattermost/flock channels. It watches the cluster
4141
for resource changes and notifies them through webhooks.
4242
4343
supported webhooks:
@@ -84,9 +84,9 @@ func initConfig() {
8484
viper.SetConfigFile(cfgFile)
8585
}
8686

87-
viper.SetConfigName(".kubewatch.yaml") // name of config file (without extension)
88-
viper.AddConfigPath("$HOME") // adding home directory as first search path
89-
viper.AutomaticEnv() // read in environment variables that match
87+
viper.SetConfigName(kubewatchConfigFile) // name of config file (without extension)
88+
viper.AddConfigPath("$HOME") // adding home directory as first search path
89+
viper.AutomaticEnv() // read in environment variables that match
9090

9191
// If a config file is found, read it in.
9292
if err := viper.ReadInConfig(); err == nil {

0 commit comments

Comments
 (0)