diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-11-29 15:52:49 +0000 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-11-29 15:52:49 +0000 |
commit | 19108ae6f38c18d14c22759be43af7368e7c2b89 (patch) | |
tree | 2cc1ebf0d9fd05e610f62301172469f3506cc6b4 | |
parent | 82e603df33359adc48caa5bc56e23084ac15abdf (diff) |
started working on help command
-rw-r--r-- | cmd/datamaps/main.go | 7 | ||||
-rw-r--r-- | pkg/datamaps/config.go | 26 |
2 files changed, 31 insertions, 2 deletions
diff --git a/cmd/datamaps/main.go b/cmd/datamaps/main.go index dc87f4f..66f78a0 100644 --- a/cmd/datamaps/main.go +++ b/cmd/datamaps/main.go @@ -12,12 +12,15 @@ import ( ) func main() { + opts := datamaps.ParseOptions() + if opts.Command == "help" { + os.Stdout.WriteString(datamaps.Usage) + os.Exit(0) + } dbpc := datamaps.NewDBPathChecker(os.UserConfigDir) if !dbpc.Check() { datamaps.SetUp() } - opts := datamaps.ParseOptions() - switch opts.Command { case "import": if err := datamaps.ImportToDB(opts); err != nil { diff --git a/pkg/datamaps/config.go b/pkg/datamaps/config.go index b21da5c..ec6f91e 100644 --- a/pkg/datamaps/config.go +++ b/pkg/datamaps/config.go @@ -11,6 +11,27 @@ const ( dbName = "datamaps.db" ) +// Help text. +const Usage = ` +usage: datamaps COMMAND [OPTIONS] + +-Managing datamap files- + +Command: datamap + +All datamap related actions. Before datamaps can do much, it must know about a datamap. +A datamap starts life as a CSV file with the format: + +cell_key,template_sheet,cell_reference,type +key1,sheet1,A10,TEXT +key2,sheet1,A11,NUMBER +... + +Options: + --import PATH Import a datamap the csv datamap at PATH + --datamapname NAME Name for imported datamap +` + // mocking funcs in go https://stackoverflow.com/questions/19167970/mock-functions-in-go // we only need the func signature to create the type. This is pretty weird, we're want to mock // os.UserHomeDir so that we can set it to something like /tmp in our tests. Here we are creating @@ -194,9 +215,14 @@ func nextString(args []string, i *int, message string) string { } func processOptions(opts *Options, allArgs []string) { + if len(allArgs) == 0 { + allArgs = append(allArgs, "help") + } switch allArgs[0] { case "import": opts.Command = "import" + case "help": + opts.Command = "help" case "datamap": opts.Command = "datamap" case "setup": |