aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
Diffstat (limited to 'pkg')
-rw-r--r--pkg/datamaps/config.go59
-rw-r--r--pkg/datamaps/db.go13
2 files changed, 61 insertions, 11 deletions
diff --git a/pkg/datamaps/config.go b/pkg/datamaps/config.go
index 888428b..191dd6f 100644
--- a/pkg/datamaps/config.go
+++ b/pkg/datamaps/config.go
@@ -107,14 +107,42 @@ func defaultDMPath() (string, error) {
return filepath.Join(dir, "Documents", "datamaps"), nil
}
+func defaultXLSXPath() (string, error) {
+ dir, err := os.UserHomeDir()
+ if err != nil {
+ return "", err
+ }
+
+ return filepath.Join(dir, "Documents", "datamaps", "import"), nil
+}
+
// Options for the whole CLI application.
type Options struct {
- Command string
- DBPath string
- DMPath string
- DMName string
+ // Command is the main CLI sub-command (e.g. "datamap" handles all datamap
+ // operations and the flags that follow pertain only to that operation.
+ Command string
+
+ // DBPath is the path to the database file.
+ DBPath string
+
+ // DMPath is the path to a datamap file.
+ DMPath string
+
+ // DMNane is the name of a datamap, whether setting or querying.
+ DMName string
+
+ // XLSXPath is the path to a directory containing ".xlsx" files for
+ // importing.
+ XLSXPath string
+
+ // ReturnName is the name of a Return, whether setting or querying.
+ ReturnName string
+
+ // DMOverwrite is currently not used.
DMOverwrite bool
- DMInitial bool
+
+ // DMInitial is currently not used.
+ DMInitial bool
}
func defaultOptions() *Options {
@@ -123,7 +151,8 @@ func defaultOptions() *Options {
log.Fatalf("Unable to get user config directory %v", err)
}
- dmpath, err := defaultDMPath()
+ dmPath, err := defaultDMPath()
+ xlsxPath, err := defaultXLSXPath()
if err != nil {
log.Fatalf("Unable to get default datamaps directory %v", err)
@@ -132,8 +161,10 @@ func defaultOptions() *Options {
return &Options{
Command: "help",
DBPath: filepath.Join(dbpath, dbName),
- DMPath: dmpath,
+ DMPath: dmPath,
DMName: "Unnamed Datamap",
+ XLSXPath: xlsxPath,
+ ReturnName: "Unnamed Return",
DMOverwrite: false,
DMInitial: false,
}
@@ -152,12 +183,14 @@ func nextString(args []string, i *int, message string) string {
func processOptions(opts *Options, allArgs []string) {
switch allArgs[0] {
- case "server":
- opts.Command = "server"
+ case "import":
+ opts.Command = "import"
case "datamap":
opts.Command = "datamap"
case "setup":
opts.Command = "setup"
+ case "server":
+ opts.Command = "server"
default:
log.Fatal("No relevant command provided.")
}
@@ -167,9 +200,13 @@ func processOptions(opts *Options, allArgs []string) {
for i := 0; i < len(allArgs[1:]); i++ {
arg := restArgs[i]
switch arg {
- case "-i", "--import":
+ case "--xlsxpath":
+ opts.XLSXPath = nextString(restArgs, &i, "xlsx directory path required")
+ case "--returnname":
+ opts.ReturnName = nextString(restArgs, &i, "return name required")
+ case "--import":
opts.DMPath = nextString(restArgs, &i, "import path required")
- case "-n", "--name":
+ case "--datamapname":
opts.DMName = nextString(restArgs, &i, "datamap name required")
case "--overwrite":
opts.DMOverwrite = true
diff --git a/pkg/datamaps/db.go b/pkg/datamaps/db.go
index ad388e2..369ff53 100644
--- a/pkg/datamaps/db.go
+++ b/pkg/datamaps/db.go
@@ -40,6 +40,7 @@ func setupDB(path string) (*sql.DB, error) {
name TEXT,
date_created TEXT
);
+
CREATE TABLE return_data(
id INTEGER PRIMARY KEY,
dml_id INTEGER,
@@ -72,6 +73,18 @@ func setupDB(path string) (*sql.DB, error) {
return db, nil
}
+// Import a directory of xlsx files to the database, using the datamap
+// to filter the data.
+func ImportToDB(opts *Options) error {
+ fmt.Printf("Import files in %s\n\tas return named %s\n\tusing datamap named %s\n", opts.XLSXPath, opts.ReturnName, opts.DMName)
+ target, err := getTargetFiles(opts.XLSXPath)
+ if err != nil {
+ return err
+ }
+ fmt.Println(target)
+ return nil
+}
+
// DatamapToDB takes a slice of datamapLine and writes it to a sqlite3 db file.
func DatamapToDB(opts *Options) error {
fmt.Printf("Importing datamap file %s and naming it %s.\n", opts.DMPath, opts.DMName)