getconfig in pttodo-cli
parent
7d98e6f0fc
commit
e8a83176aa
|
|
@ -25,6 +25,16 @@ const (
|
||||||
DUMP_DONE = "done"
|
DUMP_DONE = "done"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type config struct {
|
||||||
|
targets []string
|
||||||
|
mergeme string
|
||||||
|
root string
|
||||||
|
tags []string
|
||||||
|
search string
|
||||||
|
edit bool
|
||||||
|
dry bool
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if err := _main(); err != nil {
|
if err := _main(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
@ -32,42 +42,45 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func _main() error {
|
func _main() error {
|
||||||
|
config := getConfig()
|
||||||
|
if config.mergeme != "" {
|
||||||
|
if err := merge(config.dry, config.targets[0], config.mergeme); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if config.edit {
|
||||||
|
if err := edit(config.dry, config.targets); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dump(config.dry, os.Stdout, config.targets, config.tags, config.search, config.root)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getConfig() config {
|
||||||
defaultFilepath, ok := os.LookupEnv("PTTODO_FILE")
|
defaultFilepath, ok := os.LookupEnv("PTTODO_FILE")
|
||||||
if !ok {
|
if !ok {
|
||||||
defaultFilepath = "./todo.yaml"
|
defaultFilepath = "./todo.yaml"
|
||||||
}
|
}
|
||||||
filepath := flag.String("f", defaultFilepath, "($PTTODO_FILE) path to yaml file or dir (starting with root then alphabetical for dir)")
|
|
||||||
filepathToMergeIn := flag.String("g", "", "path to yaml file to merge into -f (modifies f)")
|
var config config
|
||||||
root := flag.String("root", DUMP_TODO, "path to pretty print ("+fmt.Sprint([]string{DUMP_ALL, DUMP_TODO, DUMP_SCHEDULED, DUMP_DONE})+")")
|
var target string
|
||||||
tags := flag.String("tags", "", "csv of all tags to find, -tag to invert")
|
flag.StringVar(&target, "f", defaultFilepath, "($PTTODO_FILE) path to yaml file or dir (starting with root then alphabetical for dir)")
|
||||||
search := flag.String("search", "", "fts case insensitive")
|
flag.StringVar(&config.mergeme, "g", "", "path to yaml file to merge into -f (modifies f)")
|
||||||
e := flag.Bool("e", false, "edit file")
|
flag.StringVar(&config.root, "root", DUMP_TODO, "path to pretty print ("+fmt.Sprint([]string{DUMP_ALL, DUMP_TODO, DUMP_SCHEDULED, DUMP_DONE})+")")
|
||||||
dry := flag.Bool("dry", false, "dry run")
|
var tagss string
|
||||||
|
flag.StringVar(&tagss, "tags", "", "csv of all tags to find, -tag to invert")
|
||||||
|
flag.StringVar(&config.search, "search", "", "fts case insensitive")
|
||||||
|
flag.BoolVar(&config.edit, "e", false, "edit file")
|
||||||
|
flag.BoolVar(&config.dry, "dry", false, "dry run")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if *filepathToMergeIn != "" {
|
|
||||||
if err := merge(*dry, *filepath, *filepathToMergeIn); err != nil {
|
config.tags = strings.Split(tagss, ",")
|
||||||
return err
|
config.targets = []string{target}
|
||||||
|
if stat, err := os.Stat(target); err == nil && stat.IsDir() {
|
||||||
|
config.targets, _ = listDir(target)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
filepaths := []string{*filepath}
|
return config
|
||||||
if stat, err := os.Stat(*filepath); err != nil && !os.IsNotExist(err) {
|
|
||||||
return err
|
|
||||||
} else if err == nil && stat.IsDir() {
|
|
||||||
filepaths, err = listDir(*filepath)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if *e {
|
|
||||||
if err := edit(*dry, filepaths); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var tagslist []string
|
|
||||||
if *tags != "" {
|
|
||||||
tagslist = strings.Split(*tags, ",")
|
|
||||||
}
|
|
||||||
return dump(*dry, os.Stdout, filepaths, tagslist, *search, *root)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func verifyRoot(root pttodo.Root) error {
|
func verifyRoot(root pttodo.Root) error {
|
||||||
|
|
|
||||||
Binary file not shown.
2
go.mod
2
go.mod
|
|
@ -5,7 +5,6 @@ go 1.17
|
||||||
require (
|
require (
|
||||||
github.com/robfig/cron/v3 v3.0.1
|
github.com/robfig/cron/v3 v3.0.1
|
||||||
gopkg.in/yaml.v2 v2.4.0
|
gopkg.in/yaml.v2 v2.4.0
|
||||||
local/sandbox/contact/contact v0.0.0-00010101000000-000000000000
|
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
|
@ -15,4 +14,3 @@ require (
|
||||||
golang.org/x/text v0.3.7 // indirect
|
golang.org/x/text v0.3.7 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
replace local/sandbox/contact/contact => ../sandbox/contact/contact
|
|
||||||
|
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
package pttodo
|
|
||||||
|
|
||||||
/*
|
|
||||||
action is something like 'send an email on trigger' but is not impl or use
|
|
||||||
*/
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"local/sandbox/contact/contact"
|
|
||||||
"net/url"
|
|
||||||
"regexp"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Action string
|
|
||||||
|
|
||||||
var (
|
|
||||||
actionEmailPattern = regexp.MustCompile(`[^@]+@.*[^\.]+\.[a-z]+`)
|
|
||||||
)
|
|
||||||
|
|
||||||
func (action Action) String() string {
|
|
||||||
return string(action)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (action Action) CB() (func() error, error) {
|
|
||||||
u, _ := url.Parse(action.String())
|
|
||||||
switch u.Scheme {
|
|
||||||
case "email":
|
|
||||||
return action.email, nil
|
|
||||||
}
|
|
||||||
if actionEmailPattern.MatchString(action.String()) {
|
|
||||||
return action.email, nil
|
|
||||||
}
|
|
||||||
return nil, errors.New("unrecognized action")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (action Action) email() error {
|
|
||||||
em := contact.NewEmailer()
|
|
||||||
_ = em
|
|
||||||
return errors.New("not impl")
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue