aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-07-19 20:20:16 +0100
committerMatthew Lemon <lemon@matthewlemon.com>2020-07-19 20:20:16 +0100
commit69854b70faa41e16ff1a2659ebc0624037b14b4f (patch)
tree4a677b8fba135529962e83c2370bd5c95b21c93e /cmd
parent12e7a848918f2c1dc08731e78ee3697762020393 (diff)
enhanced main
Diffstat (limited to 'cmd')
-rw-r--r--cmd/main.go19
1 files changed, 14 insertions, 5 deletions
diff --git a/cmd/main.go b/cmd/main.go
index 2343007..5c3ac6b 100644
--- a/cmd/main.go
+++ b/cmd/main.go
@@ -4,37 +4,46 @@ datamaps-go is a simple tool to extract from and send data to spreadsheets.
package main
import (
- "fmt"
"log"
"os"
"path/filepath"
)
-func createConfigDir() (string, error) {
+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")
if _, err := os.Stat(config_path); os.IsNotExist(err) {
log.Println("Config directory does not exist.")
- log.Println("Creating config directory.")
+ log.Printf("Creating config directory %s\n", config_path)
if err := os.Mkdir(filepath.Join(dir, "datamaps-go"), 0700); err != nil {
return "", err
}
} else {
log.Println("Config directory found.")
}
+ if _, err := os.Stat(db_path); os.IsNotExist(err) {
+ log.Println("Database does not exist.")
+ _, err = os.Create(db_path)
+ if err != nil {
+ return "", err
+ }
+ log.Printf("Creating database file at %s\n", db_path)
+ } else {
+ log.Println("Database file found.")
+ }
return dir, nil
}
// Entry point
func main() {
- dir, err := createConfigDir()
+ dir, err := setUp()
if err != nil {
log.Fatal(err)
}
- fmt.Println(dir)
}