aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
Diffstat (limited to 'pkg')
-rw-r--r--pkg/datamaps/config.go15
-rw-r--r--pkg/datamaps/db.go12
-rw-r--r--pkg/datamaps/db_test.go7
-rw-r--r--pkg/datamaps/testdata/test.dbbin135168 -> 0 bytes
4 files changed, 14 insertions, 20 deletions
diff --git a/pkg/datamaps/config.go b/pkg/datamaps/config.go
index e64f1fd..94ce068 100644
--- a/pkg/datamaps/config.go
+++ b/pkg/datamaps/config.go
@@ -7,8 +7,8 @@ import (
)
const (
- config_dir_name = "datamaps-go"
- db_name = "datamaps.db"
+ configDirName = "datamaps-go"
+ dbName = "datamaps.db"
)
func getUserConfigDir() (string, error) {
@@ -16,8 +16,8 @@ func getUserConfigDir() (string, error) {
if err != nil {
return "", err
}
- config_path := filepath.Join(dir, config_dir_name)
- return config_path, nil
+ configPath := filepath.Join(dir, configDirName)
+ return configPath, nil
}
func defaultDMPath() (string, error) {
@@ -28,9 +28,7 @@ func defaultDMPath() (string, error) {
return filepath.Join(dir, "Documents", "datamaps"), nil
}
-// TODO - need a func to replace Options.Command with the one we pass
-// Needs to use flag.NewFlagSet so we can Parse on it in main.
-
+// Options for the whole CLI application
type Options struct {
Command string
DBPath string
@@ -38,7 +36,6 @@ type Options struct {
DMName string
DMOverwrite bool
DMInitial bool
- DMData []DatamapLine
}
func defaultOptions() *Options {
@@ -57,7 +54,6 @@ func defaultOptions() *Options {
DMName: "Unnamed Datamap",
DMOverwrite: false,
DMInitial: false,
- DMData: make([]DatamapLine, 0),
}
}
@@ -98,6 +94,7 @@ func processOptions(opts *Options, allArgs []string) {
}
}
+//ParseOptions for CLI.
func ParseOptions() *Options {
opts := defaultOptions()
processOptions(opts, os.Args[1:])
diff --git a/pkg/datamaps/db.go b/pkg/datamaps/db.go
index 0f6a930..527bbb6 100644
--- a/pkg/datamaps/db.go
+++ b/pkg/datamaps/db.go
@@ -55,10 +55,12 @@ func SetupDB(path string) (*sql.DB, error) {
//func DatafmapToDB(d_path string, data []DatamapLine, dm_name string, dm_path string) error {
func DatamapToDB(opts *Options) error {
fmt.Printf("Importing datamap file %s and naming it %s.\n", opts.DMPath, opts.DMName)
- // db, err := SetupDB("/home/lemon/.config/datamaps-go/datamaps.db")
- // if err != nil {
- // return err
- // }
+
+ data, err := ReadDML(opts.DMPath)
+ if err != nil {
+ log.Fatal(err)
+ }
+
d, err := sql.Open("sqlite3", opts.DBPath)
if err != nil {
return errors.New("Cannot open that damn database file")
@@ -85,7 +87,7 @@ func DatamapToDB(opts *Options) error {
}
defer stmt_dm.Close()
defer stmt_dml.Close()
- for _, dml := range opts.DMData {
+ for _, dml := range data {
_, err = stmt_dml.Exec(1, dml.Key, dml.Sheet, dml.Cellref)
if err != nil {
return err
diff --git a/pkg/datamaps/db_test.go b/pkg/datamaps/db_test.go
index e9d5100..029121c 100644
--- a/pkg/datamaps/db_test.go
+++ b/pkg/datamaps/db_test.go
@@ -30,16 +30,11 @@ func TestOpenSQLiteFile(t *testing.T) {
}
func TestDatamapGoesIntoDB(t *testing.T) {
- d, err := ReadDML("./testdata/datamap.csv")
- if err != nil {
- t.Fatal(err)
- }
opts := Options{
DBPath: "./testdata/test.db",
DMName: "First Datamap",
- DMData: d,
}
- err = DatamapToDB(opts)
+ err := DatamapToDB(&opts)
if err != nil {
t.Errorf("Unable to write datamap to database file because %v.", err)
}
diff --git a/pkg/datamaps/testdata/test.db b/pkg/datamaps/testdata/test.db
deleted file mode 100644
index 764cbe0..0000000
--- a/pkg/datamaps/testdata/test.db
+++ /dev/null
Binary files differ