File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package entity
3
3
import (
4
4
"encoding/json"
5
5
"fmt"
6
+ "os"
6
7
7
8
pb "github.com/cocoide/commitify/pkg/grpc"
8
9
"github.com/spf13/viper"
@@ -61,8 +62,12 @@ func (c *Config) Config2PbVars() (pb.CodeFormatType, pb.LanguageType) {
61
62
62
63
func ReadConfig () (Config , error ) {
63
64
var result Config
65
+ homePath , err := os .UserHomeDir ()
66
+ if err != nil {
67
+ return result , err
68
+ }
64
69
65
- viper .AddConfigPath ("$HOME /.commitify" )
70
+ viper .AddConfigPath (homePath + " /.commitify" )
66
71
viper .SetConfigName ("config" )
67
72
viper .SetConfigType ("yaml" )
68
73
if err := viper .ReadInConfig (); err != nil {
@@ -75,7 +80,12 @@ func ReadConfig() (Config, error) {
75
80
}
76
81
77
82
func WriteConfig (config Config ) error {
78
- viper .AddConfigPath ("$HOME/.commitify" )
83
+ homePath , err := os .UserHomeDir ()
84
+ if err != nil {
85
+ return err
86
+ }
87
+
88
+ viper .AddConfigPath (homePath + "/.commitify" )
79
89
viper .SetConfigName ("config" )
80
90
viper .SetConfigType ("yaml" )
81
91
configMap := make (map [string ]interface {})
Original file line number Diff line number Diff line change @@ -9,9 +9,13 @@ import (
9
9
10
10
func main () {
11
11
// configファイルがあるかどうかを確認
12
- homePath := os .Getenv ("HOME" )
12
+ homePath , err := os .UserHomeDir ()
13
+ if err != nil {
14
+ fmt .Printf ("error of find user home dir, %v" , err )
15
+ return
16
+ }
13
17
14
- _ , err : = os .Stat (homePath + "/.commitify/config.yaml" )
18
+ _ , err = os .Stat (homePath + "/.commitify/config.yaml" )
15
19
if os .IsNotExist (err ) {
16
20
if err := os .MkdirAll (homePath + "/.commitify" , 0755 ); err != nil {
17
21
fmt .Printf ("error of make directory, %v" , err )
You can’t perform that action at this time.
0 commit comments