diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-07-20 21:14:53 +0100 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-07-20 21:14:53 +0100 |
commit | 9f5398b1aa338404403c8de4f48d343a90fe2428 (patch) | |
tree | 2d9470edb6faebfed2421a67d4a2708692e4dd01 /cmd/main.go | |
parent | 341f0bd5dfd640a0adf7cceb61fabeab7e2cebb1 (diff) |
better handling of setup but by no means perfect
Diffstat (limited to '')
-rw-r--r-- | cmd/main.go | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/cmd/main.go b/cmd/main.go index 508d9a1..1f6e4ab 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -14,14 +14,19 @@ import ( "github.com/yulqen/datamaps-go/pkg/reader" ) +const ( + config_dir_name = "datamaps-go" + db_name = "datamaps.db" +) + func setUp() (string, error) { dir, err := os.UserConfigDir() if err != nil { return "", err } // check if config folder exists - config_path := filepath.Join(dir, "datamaps-go") - db_path := filepath.Join(config_path, "datamaps.db") + config_path := filepath.Join(dir, config_dir_name) + db_path := filepath.Join(config_path, db_name) if _, err := os.Stat(config_path); os.IsNotExist(err) { log.Println("Config directory does not exist.") log.Printf("Creating config directory %s\n", config_path) @@ -81,10 +86,22 @@ func main() { fmt.Println(" overwrite:", *overwriteFlg) fmt.Println(" initial:", *initialFlg) + dir, err := os.UserConfigDir() + if err != nil { + os.Exit(1) + } + // check if config folder exists + config_path := filepath.Join(dir, config_dir_name) + + if _, err := os.Stat(config_path); os.IsNotExist(err) { + fmt.Println("Config directory and database does not exist. Run datamaps setup to fix.") + os.Exit(1) + } data, err := reader.ReadDML(*importFlg) if err != nil { log.Fatal(err) } + err = db.DatamapToDB(data, *nameFlg, *importFlg) if err != nil { log.Fatal(err) |