diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-07-23 16:45:34 +0100 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-07-23 16:45:34 +0100 |
commit | 1cd5f295939e25e6af54bf69ae9f551f23c57f23 (patch) | |
tree | 9a1c255eafef10b893b06781e8f99ed3d649bbf9 | |
parent | a3f1445eb58fb383f9012564108f948f2051869f (diff) |
progress on parsing variables - can do again datamap import and setup
Diffstat (limited to '')
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | cmd/datamaps/main.go | 21 | ||||
-rwxr-xr-x | datamaps | bin | 12830216 -> 0 bytes | |||
-rw-r--r-- | pkg/datamaps/config.go | 29 | ||||
-rw-r--r-- | pkg/datamaps/db.go | 2 |
5 files changed, 27 insertions, 26 deletions
@@ -4,3 +4,4 @@ reader/testdata/test.db go.sum dm main +datamaps diff --git a/cmd/datamaps/main.go b/cmd/datamaps/main.go index 82a655b..f37f537 100644 --- a/cmd/datamaps/main.go +++ b/cmd/datamaps/main.go @@ -52,7 +52,26 @@ func setUp() (string, error) { func main() { - _ = datamaps.ParseOptions() + opts := datamaps.ParseOptions() + + switch opts.Command { + case "datamap": + data, err := datamaps.ReadDML(opts.DMPath) + if err != nil { + log.Fatal(err) + } + opts.DMData = data + + err = datamaps.DatamapToDB(opts) + if err != nil { + log.Fatal(err) + } + case "setup": + _, err := setUp() + if err != nil { + log.Fatal(err) + } + } // switch os.Args[1] { diff --git a/datamaps b/datamaps Binary files differdeleted file mode 100755 index 50e12b7..0000000 --- a/datamaps +++ /dev/null diff --git a/pkg/datamaps/config.go b/pkg/datamaps/config.go index 91718b5..e64f1fd 100644 --- a/pkg/datamaps/config.go +++ b/pkg/datamaps/config.go @@ -1,8 +1,6 @@ package datamaps import ( - "flag" - "fmt" "log" "os" "path/filepath" @@ -63,6 +61,7 @@ func defaultOptions() *Options { } } +// nextString get the next string in a slice func nextString(args []string, i *int, message string) string { if len(args) > *i+1 { *i++ @@ -91,34 +90,16 @@ func processOptions(opts *Options, allArgs []string) { opts.DMPath = nextString(restArgs, &i, "import path required") case "-n", "--name": opts.DMName = nextString(restArgs, &i, "datamap name required") + case "--overwrite": + opts.DMOverwrite = true + case "--initial": + opts.DMInitial = true } - } } func ParseOptions() *Options { opts := defaultOptions() processOptions(opts, os.Args[1:]) - - // setup command - setupCmd := flag.NewFlagSet("setup", flag.ExitOnError) - setupCmd.Usage = func() { fmt.Println("No, you fucking idiot!") } - - // datamap command and its flags - datamapCmd := flag.NewFlagSet("datamap", flag.ExitOnError) - _ = datamapCmd.String("import", opts.DMPath, "Path to datamap") - _ = datamapCmd.String("name", opts.DMName, "The name you want to give to the imported datamap.") - _ = datamapCmd.Bool("overwrite", opts.DMOverwrite, "Start fresh with this datamap (erases existing datamap data).") - _ = datamapCmd.Bool("initial", opts.DMInitial, "This option must be used where no datamap table yet exists.") - - // server command and its flags - _ = flag.NewFlagSet("server", flag.ExitOnError) - - if len(os.Args) < 2 { - fmt.Println("Expected 'datamap' or 'setup' subcommand") - os.Exit(1) - } - return opts - } diff --git a/pkg/datamaps/db.go b/pkg/datamaps/db.go index 46d07bc..0f6a930 100644 --- a/pkg/datamaps/db.go +++ b/pkg/datamaps/db.go @@ -53,7 +53,7 @@ func SetupDB(path string) (*sql.DB, error) { // TODO - how do we avoid passing in all these params!??! //DatamapToDB takes a slice of DatamapLine and writes it to a sqlite3 db file. //func DatafmapToDB(d_path string, data []DatamapLine, dm_name string, dm_path string) error { -func DatamapToDB(opts Options) 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 { |