@@ -2,12 +2,9 @@ package main
22
33import (
44 "fmt"
5- "github.com/mitchellh/go-homedir"
65 "github.com/spf13/cobra"
76 "github.com/spf13/viper"
87 "os"
9- "path/filepath"
10- "reflect"
118 "strings"
129)
1310
@@ -20,7 +17,7 @@ var configCommand = &cobra.Command{
2017 Short : "sets or reads a config property" ,
2118 Run : func (cmd * cobra.Command , args []string ) {
2219 if len (args ) == 0 {
23- printFullConfig ()
20+ configPrintAll ()
2421 return
2522 }
2623
@@ -36,36 +33,9 @@ var configCommand = &cobra.Command{
3633 configKeyValue := strings .Split (firstArgument , "=" )
3734 configKey := configKeyValue [0 ]
3835 configValue := configKeyValue [1 ]
39- viper .Set (configKey , configValue )
40- dir , err := homedir .Dir ()
41- if err != nil {
42- _ , _ = fmt .Fprintln (os .Stderr , err )
43- }
44- err = viper .MergeInConfig ()
45- if err != nil {
46- _ , _ = fmt .Fprintln (os .Stderr , err )
47- }
48- err = viper .WriteConfigAs (filepath .Join (dir , configFileName ))
49- if err != nil {
50- _ , _ = fmt .Fprintln (os .Stderr , err )
51- }
36+ configSet (configKey , configValue )
5237 return
5338 }
54- configValue := viper .Get (configKey )
55- switch v := configValue .(type ) {
56- case string :
57- fmt .Println (v )
58- default :
59- _ , _ = fmt .Fprintf (os .Stderr , "unknown type %v\n " , reflect .TypeOf (v ))
60- }
39+ fmt .Println (configGet (configKey ))
6140 },
6241}
63-
64- func printFullConfig () {
65- err := viper .ReadInConfig ()
66- if err != nil {
67- _ , _ = fmt .Fprintln (os .Stderr , err )
68- }
69- c := viper .AllSettings ()
70- fmt .Printf ("%v\n " , c )
71- }
0 commit comments