split config.go
This commit is contained in:
47
cmd/pttodo-cli/config.go
Normal file
47
cmd/pttodo-cli/config.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
@@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@@ -23,17 +22,6 @@ const (
|
|||||||
DUMP_DONE = "done"
|
DUMP_DONE = "done"
|
||||||
)
|
)
|
||||||
|
|
||||||
type config struct {
|
|
||||||
targets []string
|
|
||||||
root string
|
|
||||||
tags []string
|
|
||||||
search string
|
|
||||||
edit bool
|
|
||||||
add string
|
|
||||||
addSchedule string
|
|
||||||
addTags string
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if err := _main(); err != nil {
|
if err := _main(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@@ -51,34 +39,6 @@ func _main() error {
|
|||||||
return dump(config)
|
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 {
|
func verifyRoot(root pttodo.Root) error {
|
||||||
f, err := ioutil.TempFile(os.TempDir(), "tmp")
|
f, err := ioutil.TempFile(os.TempDir(), "tmp")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user