getconfig in pttodo-cli
parent
7d98e6f0fc
commit
e8a83176aa
|
|
@ -25,6 +25,16 @@ const (
|
|||
DUMP_DONE = "done"
|
||||
)
|
||||
|
||||
type config struct {
|
||||
targets []string
|
||||
mergeme string
|
||||
root string
|
||||
tags []string
|
||||
search string
|
||||
edit bool
|
||||
dry bool
|
||||
}
|
||||
|
||||
func main() {
|
||||
if err := _main(); err != nil {
|
||||
panic(err)
|
||||
|
|
@ -32,42 +42,45 @@ func main() {
|
|||
}
|
||||
|
||||
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")
|
||||
if !ok {
|
||||
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)")
|
||||
root := flag.String("root", DUMP_TODO, "path to pretty print ("+fmt.Sprint([]string{DUMP_ALL, DUMP_TODO, DUMP_SCHEDULED, DUMP_DONE})+")")
|
||||
tags := flag.String("tags", "", "csv of all tags to find, -tag to invert")
|
||||
search := flag.String("search", "", "fts case insensitive")
|
||||
e := flag.Bool("e", false, "edit file")
|
||||
dry := flag.Bool("dry", false, "dry run")
|
||||
|
||||
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.mergeme, "g", "", "path to yaml file to merge into -f (modifies f)")
|
||||
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, -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()
|
||||
if *filepathToMergeIn != "" {
|
||||
if err := merge(*dry, *filepath, *filepathToMergeIn); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
config.tags = strings.Split(tagss, ",")
|
||||
config.targets = []string{target}
|
||||
if stat, err := os.Stat(target); err == nil && stat.IsDir() {
|
||||
config.targets, _ = listDir(target)
|
||||
}
|
||||
filepaths := []string{*filepath}
|
||||
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)
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
func verifyRoot(root pttodo.Root) error {
|
||||
|
|
|
|||
Binary file not shown.
2
go.mod
2
go.mod
|
|
@ -5,7 +5,6 @@ go 1.17
|
|||
require (
|
||||
github.com/robfig/cron/v3 v3.0.1
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
local/sandbox/contact/contact v0.0.0-00010101000000-000000000000
|
||||
)
|
||||
|
||||
require (
|
||||
|
|
@ -15,4 +14,3 @@ require (
|
|||
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