Skip to content

Commit c2e55b9

Browse files
committed
config: dump full config on terminal if no args are provided
1 parent 20f1ae5 commit c2e55b9

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

config/config.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package config
22

33
import (
4+
"bufio"
45
"fmt"
56
"github.com/spf13/viper"
67
"os"
@@ -47,13 +48,11 @@ func fullConfigPath(filePath string, fileName string, fileType string) string {
4748
}
4849

4950
func createConfigFileIfNonExistent(ffp string) {
50-
if _, err := os.Stat(ffp); os.IsExist(err) {
51-
return
52-
}
53-
54-
_, err := os.Create(ffp)
55-
if err != nil {
56-
panic(fmt.Sprintf("config file does not exists and wasn't able to create it: %s\n", err))
51+
if _, err := os.Stat(ffp); os.IsNotExist(err) {
52+
_, err := os.Create(ffp)
53+
if err != nil {
54+
panic(fmt.Sprintf("config file does not exists and wasn't able to create it: %s\n", err))
55+
}
5756
}
5857
}
5958

@@ -100,10 +99,19 @@ func (c *config) Set(key string, value string) {
10099
}
101100

102101
func (c *config) PrintAll() {
103-
err := viper.ReadInConfig()
102+
file, err := os.Open(c.fileFullPath)
104103
if err != nil {
105-
_, _ = fmt.Fprintln(os.Stderr, err)
104+
panic(err)
105+
}
106+
defer file.Close()
107+
108+
scanner := bufio.NewScanner(file)
109+
for scanner.Scan() {
110+
fmt.Println(scanner.Text())
111+
}
112+
113+
err = scanner.Err()
114+
if err != nil {
115+
panic(err)
106116
}
107-
wholeConfig := viper.AllSettings()
108-
fmt.Printf("%v\n", wholeConfig)
109117
}

0 commit comments

Comments
 (0)