aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-08-02 15:59:49 +0100
committerMatthew Lemon <lemon@matthewlemon.com>2020-08-02 15:59:49 +0100
commit612197f16034ce1c68bf0ebb60b39fb9ba94470c (patch)
tree7c08bb3dec6ab01882161f6e4b5a6b81c8a63a4f
parent1f442dfc4b1478e942540cc07ea21711c99a1877 (diff)
added createdatamap command
-rw-r--r--cmd/datamaps/main.go4
-rw-r--r--pkg/datamaps/config.go4
-rw-r--r--pkg/datamaps/writer.go9
-rw-r--r--pkg/datamaps/writer_test.go2
4 files changed, 14 insertions, 5 deletions
diff --git a/cmd/datamaps/main.go b/cmd/datamaps/main.go
index 0c1862d..dc87f4f 100644
--- a/cmd/datamaps/main.go
+++ b/cmd/datamaps/main.go
@@ -32,6 +32,10 @@ func main() {
if err != nil {
log.Fatal(err)
}
+ case "createmaster":
+ if err := datamaps.CreateMaster(opts); err != nil {
+ log.Fatal(err)
+ }
case "server":
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
diff --git a/pkg/datamaps/config.go b/pkg/datamaps/config.go
index f370ba4..b21da5c 100644
--- a/pkg/datamaps/config.go
+++ b/pkg/datamaps/config.go
@@ -203,6 +203,8 @@ func processOptions(opts *Options, allArgs []string) {
opts.Command = "setup"
case "server":
opts.Command = "server"
+ case "createmaster":
+ opts.Command = "createmaster"
default:
log.Fatal("No relevant command provided.")
}
@@ -224,6 +226,8 @@ func processOptions(opts *Options, allArgs []string) {
opts.DMOverwrite = true
case "--initial":
opts.DMInitial = true
+ case "--masteroutputdir":
+ opts.MasterOutPutPath = nextString(restArgs, &i, "master output directory required")
}
}
}
diff --git a/pkg/datamaps/writer.go b/pkg/datamaps/writer.go
index 8e721d0..defb656 100644
--- a/pkg/datamaps/writer.go
+++ b/pkg/datamaps/writer.go
@@ -12,15 +12,17 @@ import (
_ "github.com/mattn/go-sqlite3"
)
-func ExportMaster(opts *Options) error {
+// CreateMaster creates a master spreadsheet for a specific return given,
+// based on a datamap name - both of which already need to be in the database,
+// along with the data associated with the return. The datamap and return data
+// must already have been imported.
+func CreateMaster(opts *Options) error {
wb := xlsx.NewFile()
sh, err := wb.AddSheet("Master Data")
if err != nil {
return fmt.Errorf("cannot add 'Master Data' sheet to new XLSX file: %v", err)
}
- // SQLITE CODE
-
db, err := sql.Open("sqlite3", opts.DBPath)
if err != nil {
return fmt.Errorf("cannot open database %v", err)
@@ -103,7 +105,6 @@ func ExportMaster(opts *Options) error {
}
for masterRow := 0; masterRow < len(datamapKeys); masterRow++ {
- log.Printf("Writing to masterRow which is %d", masterRow)
r, err := sh.AddRowAtIndex(masterRow)
if err != nil {
return fmt.Errorf("cannot create row %d in output spreadsheet: %v", masterRow, err)
diff --git a/pkg/datamaps/writer_test.go b/pkg/datamaps/writer_test.go
index 319544c..92af664 100644
--- a/pkg/datamaps/writer_test.go
+++ b/pkg/datamaps/writer_test.go
@@ -40,7 +40,7 @@ func TestWriteMaster(t *testing.T) {
t.Fatalf("cannot read test XLSX files needed before exporting to master - %v", err)
}
- if err := ExportMaster(&opts); err != nil {
+ if err := CreateMaster(&opts); err != nil {
t.Error(err)
}
}