From 7a20f3fdda5d041cf92c38dd50147e6520d25543 Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Mon, 6 Nov 2023 10:37:34 -0700 Subject: [PATCH] split config.go --- cmd/pttodo-cli/config.go | 47 ++++++++++++++++++++++++++++++++++++++++ cmd/pttodo-cli/main.go | 40 ---------------------------------- 2 files changed, 47 insertions(+), 40 deletions(-) create mode 100644 cmd/pttodo-cli/config.go diff --git a/cmd/pttodo-cli/config.go b/cmd/pttodo-cli/config.go new file mode 100644 index 0000000..b9d629a --- /dev/null +++ b/cmd/pttodo-cli/config.go @@ -0,0 +1,47 @@ +package main + +import ( + "flag" + "fmt" + "os" + "strings" +) + +type config struct { + targets []string + root string + tags []string + search string + edit bool + add string + addSchedule string + addTags string +} + +func getConfig() config { + defaultFilepath := os.Getenv("PTTODO_FILE") + if defaultFilepath == "" { + defaultFilepath = "./todo.yaml" + } + + var config config + var target string + flag.StringVar(&target, "f", defaultFilepath, "($PTTODO_FILE) path to yaml file or dir (starting with root then alphabetical for dir)") + flag.StringVar(&config.root, "root", DUMP_TODO, "path to pretty print ("+fmt.Sprint([]string{DUMP_ALL, DUMP_TODO, DUMP_SCHEDULED, DUMP_DONE})+")") + var tagss string + flag.StringVar(&tagss, "tags", "", "csv of all tags to find, -x to invert") + flag.StringVar(&config.search, "search", "", "fts case insensitive") + flag.BoolVar(&config.edit, "e", false, "edit file") + flag.StringVar(&config.add, "add", "", "todo to add") + flag.StringVar(&config.addSchedule, "add-schedule", "", "todo to add schedule") + flag.StringVar(&config.addTags, "add-tags", "", "todo to add csv tags") + flag.Parse() + + config.tags = strings.Split(tagss, ",") + config.targets = []string{target} + if stat, err := os.Stat(target); err == nil && stat.IsDir() { + config.targets, _ = listDir(target) + } + + return config +} diff --git a/cmd/pttodo-cli/main.go b/cmd/pttodo-cli/main.go index c8668f1..c0eac4c 100644 --- a/cmd/pttodo-cli/main.go +++ b/cmd/pttodo-cli/main.go @@ -2,7 +2,6 @@ package main import ( "bytes" - "flag" "fmt" "io" "io/ioutil" @@ -23,17 +22,6 @@ const ( DUMP_DONE = "done" ) -type config struct { - targets []string - root string - tags []string - search string - edit bool - add string - addSchedule string - addTags string -} - func main() { if err := _main(); err != nil { panic(err) @@ -51,34 +39,6 @@ func _main() error { return dump(config) } -func getConfig() config { - defaultFilepath := os.Getenv("PTTODO_FILE") - if defaultFilepath == "" { - defaultFilepath = "./todo.yaml" - } - - var config config - var target string - flag.StringVar(&target, "f", defaultFilepath, "($PTTODO_FILE) path to yaml file or dir (starting with root then alphabetical for dir)") - flag.StringVar(&config.root, "root", DUMP_TODO, "path to pretty print ("+fmt.Sprint([]string{DUMP_ALL, DUMP_TODO, DUMP_SCHEDULED, DUMP_DONE})+")") - var tagss string - flag.StringVar(&tagss, "tags", "", "csv of all tags to find, -x to invert") - flag.StringVar(&config.search, "search", "", "fts case insensitive") - flag.BoolVar(&config.edit, "e", false, "edit file") - flag.StringVar(&config.add, "add", "", "todo to add") - flag.StringVar(&config.addSchedule, "add-schedule", "", "todo to add schedule") - flag.StringVar(&config.addTags, "add-tags", "", "todo to add csv tags") - flag.Parse() - - config.tags = strings.Split(tagss, ",") - config.targets = []string{target} - if stat, err := os.Stat(target); err == nil && stat.IsDir() { - config.targets, _ = listDir(target) - } - - return config -} - func verifyRoot(root pttodo.Root) error { f, err := ioutil.TempFile(os.TempDir(), "tmp") if err != nil {