aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-07-23 16:30:48 +0100
committerMatthew Lemon <lemon@matthewlemon.com>2020-07-23 16:30:48 +0100
commita3f1445eb58fb383f9012564108f948f2051869f (patch)
tree70377d49cd644e029c4103551d6001f17d0d1a99
parentdd3afa6b53db767522bf7fe93facd2bc2605a1c8 (diff)
working on parsing the arguments manually
-rw-r--r--pkg/datamaps/config.go33
1 files changed, 30 insertions, 3 deletions
diff --git a/pkg/datamaps/config.go b/pkg/datamaps/config.go
index ffe14db..91718b5 100644
--- a/pkg/datamaps/config.go
+++ b/pkg/datamaps/config.go
@@ -63,15 +63,42 @@ func defaultOptions() *Options {
}
}
-func ParseOptions() *Options {
- opts := defaultOptions()
+func nextString(args []string, i *int, message string) string {
+ if len(args) > *i+1 {
+ *i++
+ } else {
+ log.Fatal(message)
+ }
+ return args[*i]
+}
- switch os.Args[1] {
+func processOptions(opts *Options, allArgs []string) {
+ switch allArgs[0] {
case "server":
opts.Command = "server"
case "datamap":
opts.Command = "datamap"
+ case "setup":
+ opts.Command = "setup"
+ default:
+ log.Fatal("No relevant command provided.")
+ }
+ restArgs := allArgs[1:]
+ for i := 0; i < len(allArgs[1:]); i++ {
+ arg := restArgs[i]
+ switch arg {
+ case "-i", "--import":
+ opts.DMPath = nextString(restArgs, &i, "import path required")
+ case "-n", "--name":
+ opts.DMName = nextString(restArgs, &i, "datamap name required")
+ }
+
}
+}
+
+func ParseOptions() *Options {
+ opts := defaultOptions()
+ processOptions(opts, os.Args[1:])
// setup command
setupCmd := flag.NewFlagSet("setup", flag.ExitOnError)