aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/datamaps/main.go43
1 files changed, 1 insertions, 42 deletions
diff --git a/cmd/datamaps/main.go b/cmd/datamaps/main.go
index 32b7ce8..15d635a 100644
--- a/cmd/datamaps/main.go
+++ b/cmd/datamaps/main.go
@@ -7,51 +7,10 @@ import (
"fmt"
"log"
"net/http"
- "os"
- "path/filepath"
"github.com/yulqen/datamaps-go/pkg/datamaps"
)
-const (
- configDirName = "datamaps-go"
- dbName = "datamaps.db"
-)
-
-func setUp() (string, error) {
- dir, err := os.UserConfigDir()
- if err != nil {
- return "", err
- }
- // check if config folder exists
- configPath := filepath.Join(dir, configDirName)
- dbPath := filepath.Join(configPath, dbName)
- 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 {
- return "", err
- }
- } else {
- log.Println("Config directory found.")
- }
- if _, err := os.Stat(dbPath); os.IsNotExist(err) {
- log.Println("Database does not exist.")
- _, err = os.Create(dbPath)
- if err != nil {
- return "", err
- }
- log.Printf("Creating database file at %s\n", dbPath)
- _, err := datamaps.SetupDB(dbPath)
- if err != nil {
- return "", err
- }
- } else {
- log.Println("Database file found.")
- }
- return dir, nil
-}
-
func main() {
opts := datamaps.ParseOptions()
@@ -62,7 +21,7 @@ func main() {
log.Fatal(err)
}
case "setup":
- _, err := setUp()
+ _, err := datamaps.SetUp()
if err != nil {
log.Fatal(err)
}