aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cmd/datamaps/main.go9
-rw-r--r--pkg/datamaps/config.go6
-rw-r--r--pkg/datamaps/config_test.go2
3 files changed, 8 insertions, 9 deletions
diff --git a/cmd/datamaps/main.go b/cmd/datamaps/main.go
index b421223..7841e95 100644
--- a/cmd/datamaps/main.go
+++ b/cmd/datamaps/main.go
@@ -7,15 +7,16 @@ import (
"fmt"
"log"
"net/http"
+ "os"
"github.com/yulqen/datamaps-go/pkg/datamaps"
)
func main() {
- // env := datamaps.DetectConfig()
- // if !env {
- // datamaps.SetUp()
- // }
+ dbpc := datamaps.NewDBPathChecker(os.UserConfigDir)
+ if !dbpc.Check() {
+ datamaps.SetUp()
+ }
opts := datamaps.ParseOptions()
switch opts.Command {
diff --git a/pkg/datamaps/config.go b/pkg/datamaps/config.go
index 8dc8896..6635761 100644
--- a/pkg/datamaps/config.go
+++ b/pkg/datamaps/config.go
@@ -1,7 +1,6 @@
package datamaps
import (
- "fmt"
"log"
"os"
"path/filepath"
@@ -32,14 +31,13 @@ func NewDBPathChecker(h GetUserConfigDir) *DBPathChecker {
return &DBPathChecker{getUserConfigDir: h}
}
-func (db *DBPathChecker) check() bool {
+func (db *DBPathChecker) Check() bool {
userConfig, err := db.getUserConfigDir()
if err != nil {
log.Fatal(err)
}
dbPath := filepath.Join(userConfig, "datamaps.db")
if _, err := os.Stat(dbPath); os.IsNotExist(err) {
- fmt.Fprintf(os.Stderr, "db does not exist\n")
return false
}
return true
@@ -57,7 +55,7 @@ func SetUp() (string, error) {
if _, err := os.Stat(configPath); os.IsNotExist(err) {
log.Println("Config directory does not exist.")
log.Printf("Creating config directory %s\n", configPath)
- if err := os.Mkdir(filepath.Join(dir, "datamaps-go"), 0700); err != nil {
+ if err := os.Mkdir(filepath.Join(dir, "datamaps"), 0700); err != nil {
return "", err
}
} else {
diff --git a/pkg/datamaps/config_test.go b/pkg/datamaps/config_test.go
index ad19879..2dfa665 100644
--- a/pkg/datamaps/config_test.go
+++ b/pkg/datamaps/config_test.go
@@ -26,7 +26,7 @@ func TestDBDetect(t *testing.T) {
}()
dbpc := NewDBPathChecker(mockConfigDir)
- h := dbpc.check()
+ h := dbpc.Check()
if !h {
t.Error("the db file should be found but isn't")
}