Skip to content

Commit 354b9e8

Browse files
committed
fix: 設定ファイルがあるかどうかの確認を、起動時に行うように変更
1 parent b835d8b commit 354b9e8

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
package main
22

33
import (
4+
"fmt"
5+
"os"
6+
47
"github.com/cocoide/commitify/cmd"
58
)
69

710
func main() {
11+
// configファイルがあるかどうかを確認
12+
_, err := os.Stat("config.yaml")
13+
if os.IsNotExist(err) {
14+
if _, err := os.Create("config.yaml"); err != nil {
15+
fmt.Printf("error creating config file, %s", err.Error())
16+
}
17+
}
18+
819
cmd.Execute()
920
}

util/config.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package util
33
import (
44
"encoding/json"
55
"fmt"
6-
"os"
76

87
"github.com/cocoide/commitify/internal/entity"
98
"github.com/spf13/viper"
@@ -12,14 +11,6 @@ import (
1211
func ReadConfig() (*entity.Config, error) {
1312
var result entity.Config
1413

15-
// configファイルがあるかどうかを確認
16-
_, err := os.Stat("config.yaml")
17-
if os.IsNotExist(err) {
18-
if _, err := os.Create("config.yaml"); err != nil {
19-
return &result, fmt.Errorf("error creating config file, %s", err.Error())
20-
}
21-
}
22-
2314
viper.AddConfigPath(".")
2415
viper.SetConfigName("config")
2516
viper.SetConfigType("yaml")
@@ -33,14 +24,6 @@ func ReadConfig() (*entity.Config, error) {
3324
}
3425

3526
func WriteConfig(config *entity.Config) error {
36-
// configファイルがあるかどうかを確認
37-
_, err := os.Stat("config.yaml")
38-
if !os.IsNotExist(err) {
39-
if _, err := os.Create("config.yaml"); err != nil {
40-
return fmt.Errorf("error creating config file, %s", err.Error())
41-
}
42-
}
43-
4427
viper.AddConfigPath(".")
4528
viper.SetConfigName("config")
4629
viper.SetConfigType("yaml")

0 commit comments

Comments
 (0)