bake listing files not cached in config
parent
8dacd8da5d
commit
d36f9e74b3
17
cmd/add.go
17
cmd/add.go
|
|
@ -18,23 +18,18 @@ func add(config *config) error {
|
||||||
Schedule: pttodo.Schedule(config.addSchedule),
|
Schedule: pttodo.Schedule(config.addSchedule),
|
||||||
Tags: config.addTags,
|
Tags: config.addTags,
|
||||||
}
|
}
|
||||||
newTarget, err := _add(config.targets, v)
|
return _add(config.Targets()[0], v)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
config.targets = append(config.targets, newTarget)
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func _add(filepaths []string, todo pttodo.Todo) (string, error) {
|
func _add(filepath string, todo pttodo.Todo) error {
|
||||||
target := filepaths[0] + ".todo." + uuid.New().String()
|
target := filepath + ".todo." + uuid.New().String()
|
||||||
|
|
||||||
c, err := yaml.Marshal([]pttodo.Todo{todo})
|
c, err := yaml.Marshal([]pttodo.Todo{todo})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return err
|
||||||
} else if err := ioutil.WriteFile(target, c, os.ModePerm); err != nil {
|
} else if err := ioutil.WriteFile(target, c, os.ModePerm); err != nil {
|
||||||
return "", err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return target, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,12 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type config struct {
|
type config struct {
|
||||||
targets []string
|
target string
|
||||||
root string
|
root string
|
||||||
tags []string
|
tags []string
|
||||||
search string
|
search string
|
||||||
|
|
@ -25,8 +26,7 @@ func getConfig() config {
|
||||||
}
|
}
|
||||||
|
|
||||||
var config config
|
var config config
|
||||||
var target string
|
flag.StringVar(&config.target, "f", defaultFilepath, "($PTTODO_FILE) path to yaml file or dir (starting with root then alphabetical for dir)")
|
||||||
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})+")")
|
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
|
var tagss string
|
||||||
flag.StringVar(&tagss, "tags", "", "csv of all tags to find, -x to invert")
|
flag.StringVar(&tagss, "tags", "", "csv of all tags to find, -x to invert")
|
||||||
|
|
@ -38,10 +38,37 @@ func getConfig() config {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
config.tags = strings.Split(tagss, ",")
|
config.tags = strings.Split(tagss, ",")
|
||||||
config.targets = []string{target}
|
|
||||||
if stat, err := os.Stat(target); err == nil && stat.IsDir() {
|
config.Targets()
|
||||||
config.targets, _ = listDir(target)
|
|
||||||
}
|
|
||||||
|
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (config config) Targets() []string {
|
||||||
|
result, err := config.targets()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func (config config) targets() ([]string, error) {
|
||||||
|
patterns := []string{config.target, fmt.Sprintf("%s.*", config.target)}
|
||||||
|
if stat, err := os.Stat(config.target); err == nil && stat.IsDir() {
|
||||||
|
patterns = []string{fmt.Sprintf("%s/*", config.target)}
|
||||||
|
}
|
||||||
|
|
||||||
|
result := make([]string, 0, 1)
|
||||||
|
for _, pattern := range patterns {
|
||||||
|
results, err := filepath.Glob(pattern)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
result = append(result, results...)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(result) == 0 {
|
||||||
|
return []string{config.target}, nil
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
|
||||||
16
cmd/dump.go
16
cmd/dump.go
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gogs.inhome.blapointe.com/bel/pttodo/pttodo"
|
"gogs.inhome.blapointe.com/bel/pttodo/pttodo"
|
||||||
|
|
@ -13,12 +14,25 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func dump(config config) error {
|
func dump(config config) error {
|
||||||
return _dump(os.Stdout, config.targets, config.tags, config.search, config.root)
|
return _dump(os.Stdout, config.Targets(), config.tags, config.search, config.root)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _dump(writer io.Writer, filepaths []string, tags []string, search, rootDisplay string) error {
|
func _dump(writer io.Writer, filepaths []string, tags []string, search, rootDisplay string) error {
|
||||||
var root pttodo.Root
|
var root pttodo.Root
|
||||||
|
|
||||||
|
for _, p := range filepaths {
|
||||||
|
results, err := filepath.Glob(p + ".*")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, result := range results {
|
||||||
|
if result == p {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
filepaths = append(filepaths, result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, filepath := range filepaths {
|
for _, filepath := range filepaths {
|
||||||
reader, err := filePathReader(filepath)
|
reader, err := filePathReader(filepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ func edit(config *config) error {
|
||||||
if !config.edit {
|
if !config.edit {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return _edit(config.targets)
|
return _edit(config.Targets())
|
||||||
}
|
}
|
||||||
|
|
||||||
func _edit(filepaths []string) error {
|
func _edit(filepaths []string) error {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue