move pttodo-cli up from /cmd/
This commit is contained in:
47
cmd/config.go
Normal file
47
cmd/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
|
||||
}
|
||||
Reference in New Issue
Block a user