aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGrant Ammons <gammons@gmail.com>2017-03-07 15:44:48 -0500
committerGitHub <noreply@github.com>2017-03-07 15:44:48 -0500
commit21725dc9696518beb5c52bdf253963b09a74c9a5 (patch)
tree5a12f1e017671fc05cbf4e355c74931c75267341
parent90a35514e2045ec60c5d56dcdae8a4e436769816 (diff)
parent8d11447546665c5ef8402ffd23b9ff5d2943bb24 (diff)
Merge pull request #41 from gammons/revert-32-master
Revert "Global repo file as the default"
-rw-r--r--todolist/file_store.go25
1 files changed, 5 insertions, 20 deletions
diff --git a/todolist/file_store.go b/todolist/file_store.go
index 4a7f0e0..5413295 100644
--- a/todolist/file_store.go
+++ b/todolist/file_store.go
@@ -5,7 +5,6 @@ import (
"fmt"
"io/ioutil"
"os"
- "os/user"
)
type FileStore struct {
@@ -14,36 +13,22 @@ type FileStore struct {
}
func NewFileStore() *FileStore {
- localrepo := ".todos.json"
- usr, _ := user.Current()
- homerepo := fmt.Sprintf("%s/.todos.json", usr.HomeDir)
- _, err1 := os.Stat(localrepo)
- _, err2 := os.Stat(homerepo)
-
- if err1 == nil {
- return &FileStore{FileLocation: localrepo, Loaded: false}
- } else if err2 == nil {
- return &FileStore{FileLocation: homerepo, Loaded: false}
- } else {
- fmt.Println("No todo file found!")
- fmt.Println("You may run 'todo init' to initialize an empty repo in working directory.")
- os.Exit(1)
- return nil
- }
+ return &FileStore{FileLocation: ".todos.json", Loaded: false}
}
func (f *FileStore) Load() ([]*Todo, error) {
data, err := ioutil.ReadFile(f.FileLocation)
if err != nil {
- fmt.Println("Error reading", f.FileLocation, "by", err)
+ fmt.Println("No todo file found!")
+ fmt.Println("Initialize a new todo repo by running 'todo init'")
return nil, err
- os.Exit(1)
+ os.Exit(0)
}
var todos []*Todo
jerr := json.Unmarshal(data, &todos)
if jerr != nil {
- fmt.Println("Error reading", f.FileLocation, "by", jerr)
+ fmt.Println("Error reading json data", jerr)
return nil, jerr
os.Exit(1)
}