aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/datamaps/config.go
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-07-23 16:45:34 +0100
committerMatthew Lemon <lemon@matthewlemon.com>2020-07-23 16:45:34 +0100
commit1cd5f295939e25e6af54bf69ae9f551f23c57f23 (patch)
tree9a1c255eafef10b893b06781e8f99ed3d649bbf9 /pkg/datamaps/config.go
parenta3f1445eb58fb383f9012564108f948f2051869f (diff)
progress on parsing variables - can do again datamap import and setup
Diffstat (limited to 'pkg/datamaps/config.go')
-rw-r--r--pkg/datamaps/config.go29
1 files changed, 5 insertions, 24 deletions
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
-
}