aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <matt@matthewlemon.com>2020-07-23 14:02:10 +0100
committerMatthew Lemon <matt@matthewlemon.com>2020-07-23 14:02:10 +0100
commit850be5e72157a9e56e52547e3385f419ca189880 (patch)
treedbb320b02c43429ed9212b98344ed2438b147f9c
parente910620988760b054bd669f6f6847ccf96ab717a (diff)
starting to reconfigure all option and args handling
-rw-r--r--cmd/datamaps/main.go110
-rw-r--r--go.mod1
-rw-r--r--pkg/datamaps/config.go15
3 files changed, 64 insertions, 62 deletions
diff --git a/cmd/datamaps/main.go b/cmd/datamaps/main.go
index 322bf8d..82a655b 100644
--- a/cmd/datamaps/main.go
+++ b/cmd/datamaps/main.go
@@ -4,9 +4,7 @@ datamaps-go is a simple tool to extract from and send data to spreadsheets.
package main
import (
- "fmt"
"log"
- "net/http"
"os"
"path/filepath"
@@ -54,64 +52,64 @@ func setUp() (string, error) {
func main() {
- opts := datamaps.ParseOptions()
+ _ = datamaps.ParseOptions()
- switch os.Args[1] {
+ // switch os.Args[1] {
- case "server":
- opts.Command.Parse(os.Args[2:])
- http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
- if r.URL.Path != "/" {
- http.NotFound(w, r)
- return
- }
- fmt.Fprintf(w, "Welcome to datamaps!")
- // or you could write it thus
- // w.Write([]byte("Hello from Snippetbox"))
- })
- log.Println("Starting server on :8080")
- err := http.ListenAndServe(":8080", nil)
- log.Fatal(err)
+ // case "server":
+ // opts.Command.Parse(os.Args[2:])
+ // http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ // if r.URL.Path != "/" {
+ // http.NotFound(w, r)
+ // return
+ // }
+ // fmt.Fprintf(w, "Welcome to datamaps!")
+ // // or you could write it thus
+ // // w.Write([]byte("Hello from Snippetbox"))
+ // })
+ // log.Println("Starting server on :8080")
+ // err := http.ListenAndServe(":8080", nil)
+ // log.Fatal(err)
- case "datamap":
- datamapCmd.Parse(os.Args[2:])
- fmt.Println("subcommand 'datamap'")
- fmt.Println(" import:", *dmPath)
- fmt.Println(" name:", *dmName)
- fmt.Println(" overwrite:", *dmOverwrite)
- fmt.Println(" initial:", *dmInitial)
+ // case "datamap":
+ // datamapCmd.Parse(os.Args[2:])
+ // fmt.Println("subcommand 'datamap'")
+ // fmt.Println(" import:", *dmPath)
+ // fmt.Println(" name:", *dmName)
+ // fmt.Println(" overwrite:", *dmOverwrite)
+ // fmt.Println(" initial:", *dmInitial)
- dir, err := os.UserConfigDir()
- if err != nil {
- os.Exit(1)
- }
- // check if config folder exists
- config_path := filepath.Join(dir, config_dir_name)
- if _, err := os.Stat(config_path); os.IsNotExist(err) {
- fmt.Println("Config directory and database does not exist. Run datamaps setup to fix.")
- os.Exit(1)
- }
- // Here we actually read the data from the file
- data, err := datamaps.ReadDML(opts.ImportPath)
- if err != nil {
- log.Fatal(err)
- }
- opts.DMData = data
+ // dir, err := os.UserConfigDir()
+ // if err != nil {
+ // os.Exit(1)
+ // }
+ // // check if config folder exists
+ // config_path := filepath.Join(dir, config_dir_name)
+ // if _, err := os.Stat(config_path); os.IsNotExist(err) {
+ // fmt.Println("Config directory and database does not exist. Run datamaps setup to fix.")
+ // os.Exit(1)
+ // }
+ // // Here we actually read the data from the file
+ // data, err := datamaps.ReadDML(opts.ImportPath)
+ // if err != nil {
+ // log.Fatal(err)
+ // }
+ // opts.DMData = data
- opts.DBPath = filepath.Join(config_path, db_name)
- err = datamaps.DatamapToDB(opts)
- if err != nil {
- log.Fatal(err)
- }
- case "setup":
- setupCmd.Parse(os.Args[2:])
- _, err := setUp()
- if err != nil {
- log.Fatal(err)
- }
+ // opts.DBPath = filepath.Join(config_path, db_name)
+ // err = datamaps.DatamapToDB(opts)
+ // if err != nil {
+ // log.Fatal(err)
+ // }
+ // case "setup":
+ // setupCmd.Parse(os.Args[2:])
+ // _, err := setUp()
+ // if err != nil {
+ // log.Fatal(err)
+ // }
- default:
- fmt.Println("Do not recognised that command. Expected 'datamap' subcommand.")
- os.Exit(1)
- }
+ // default:
+ // fmt.Println("Do not recognised that command. Expected 'datamap' subcommand.")
+ // os.Exit(1)
+ // }
}
diff --git a/go.mod b/go.mod
index d3b11f0..79eedf2 100644
--- a/go.mod
+++ b/go.mod
@@ -8,5 +8,4 @@ require (
github.com/tealeg/xlsx v1.0.5
github.com/urfave/cli/v2 v2.2.0
github.com/yulqen/coords v0.1.0
- golang.org/x/tools v0.0.0-20200722181740-bd1e9de8d890 // indirect
)
diff --git a/pkg/datamaps/config.go b/pkg/datamaps/config.go
index c182267..1bc65ec 100644
--- a/pkg/datamaps/config.go
+++ b/pkg/datamaps/config.go
@@ -66,19 +66,24 @@ func defaultOptions() *Options {
func ParseOptions() *Options {
opts := defaultOptions()
+ switch os.Args[1] {
+ case "server":
+ opts.Command = "server"
+ }
+
// 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)
- dmPath := datamapCmd.String("import", opts.DMPath, "Path to datamap")
- dmName := datamapCmd.String("name", opts.DMName, "The name you want to give to the imported datamap.")
- dmOverwrite := datamapCmd.Bool("overwrite", opts.DMOverwrite, "Start fresh with this datamap (erases existing datamap data).")
- dmInitial := datamapCmd.Bool("initial", opts.DMInitial, "This option must be used where no datamap table yet exists.")
+ _ = 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
- serverCmd := flag.NewFlagSet("server", flag.ExitOnError)
+ _ = flag.NewFlagSet("server", flag.ExitOnError)
if len(os.Args) < 2 {
fmt.Println("Expected 'datamap' or 'setup' subcommand")