drop some args
This commit is contained in:
@@ -31,12 +31,10 @@ const (
|
||||
|
||||
type config struct {
|
||||
targets []string
|
||||
mergeme string
|
||||
root string
|
||||
tags []string
|
||||
search string
|
||||
edit bool
|
||||
dry bool
|
||||
add string
|
||||
addSchedule string
|
||||
addTags string
|
||||
@@ -50,27 +48,22 @@ 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.add != "" {
|
||||
v := pttodo.Todo{
|
||||
Todo: config.add,
|
||||
Schedule: pttodo.Schedule(config.addSchedule),
|
||||
Tags: config.addTags,
|
||||
}
|
||||
if err := add(config.dry, config.targets, v); err != nil {
|
||||
if err := add(config.targets, v); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if config.edit {
|
||||
if err := edit(config.dry, config.targets); err != nil {
|
||||
if err := edit(config.targets); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return dump(config.dry, os.Stdout, config.targets, config.tags, config.search, config.root)
|
||||
return dump(os.Stdout, config.targets, config.tags, config.search, config.root)
|
||||
}
|
||||
|
||||
func getConfig() config {
|
||||
@@ -82,13 +75,11 @@ func getConfig() config {
|
||||
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, -x 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.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")
|
||||
@@ -122,13 +113,13 @@ func verifyRoot(root pttodo.Root) error {
|
||||
}
|
||||
|
||||
func verifyFile(path string) error {
|
||||
if err := dump(true, io.Discard, []string{path}, nil, "", DUMP_ALL); err != nil {
|
||||
if err := dump(io.Discard, []string{path}, nil, "", DUMP_ALL); err != nil {
|
||||
return fmt.Errorf("failed verifying file %s: %w", path, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func add(dry bool, filepaths []string, todo pttodo.Todo) error {
|
||||
func add(filepaths []string, todo pttodo.Todo) error {
|
||||
target := filepaths[0]
|
||||
var original pttodo.Root
|
||||
|
||||
@@ -146,9 +137,6 @@ func add(dry bool, filepaths []string, todo pttodo.Todo) error {
|
||||
c, err := yaml.Marshal(original)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if dry {
|
||||
log.Printf("wouldve written...\n%s", c)
|
||||
return nil
|
||||
} else if err := ioutil.WriteFile(target, c, os.ModePerm); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -156,7 +144,7 @@ func add(dry bool, filepaths []string, todo pttodo.Todo) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func edit(dry bool, filepaths []string) error {
|
||||
func edit(filepaths []string) error {
|
||||
tempDir, err := ioutil.TempDir(os.TempDir(), "edit-pttodo-*")
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -208,9 +196,6 @@ func edit(dry bool, filepaths []string) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
if dry {
|
||||
return nil
|
||||
}
|
||||
for _, target := range filepaths {
|
||||
r, err := filePathReader(path.Join(tempDir, path.Base(target)))
|
||||
if err != nil {
|
||||
@@ -255,7 +240,7 @@ func edit(dry bool, filepaths []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func _edit(dry bool, filepaths []string) error {
|
||||
func _edit(filepaths []string) error {
|
||||
tempDir, err := ioutil.TempDir(os.TempDir(), "edit-pttodo")
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -330,10 +315,6 @@ func _edit(dry bool, filepaths []string) error {
|
||||
//log.Printf("no changes to %s", filepath)
|
||||
return nil
|
||||
}
|
||||
if dry {
|
||||
log.Printf("would've saved %s as %s", tempFile, filepath)
|
||||
return nil
|
||||
}
|
||||
return os.Rename(tempFile, filepath)
|
||||
}
|
||||
save := func() error {
|
||||
@@ -350,9 +331,7 @@ func _edit(dry bool, filepaths []string) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if !dry {
|
||||
os.RemoveAll(tempDir)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -399,7 +378,7 @@ func vimd(d string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func merge(dry bool, filepath string, mergeTargetFilePath string) error {
|
||||
func merge(filepath string, mergeTargetFilePath string) error {
|
||||
baseReader, err := filePathReader(filepath)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -435,10 +414,6 @@ func merge(dry bool, filepath string, mergeTargetFilePath string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if dry {
|
||||
log.Printf("would've moved %s to %s when adding %s", tmppath, filepath, mergeTargetFilePath)
|
||||
return nil
|
||||
}
|
||||
return os.Rename(tmppath, filepath)
|
||||
}
|
||||
|
||||
@@ -458,7 +433,7 @@ func marshalRootToTempFile(root pttodo.Root) (string, error) {
|
||||
return filepath, err
|
||||
}
|
||||
|
||||
func dump(dry bool, 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
|
||||
|
||||
for _, filepath := range filepaths {
|
||||
@@ -482,7 +457,6 @@ func dump(dry bool, writer io.Writer, filepaths []string, tags []string, search,
|
||||
|
||||
root2.MoveScheduledToTodo()
|
||||
|
||||
if !dry {
|
||||
if !root2.Equals(root2post) {
|
||||
log.Printf("refreshing %s", filepath)
|
||||
b3, err := yaml.Marshal(root2)
|
||||
@@ -495,7 +469,6 @@ func dump(dry bool, writer io.Writer, filepaths []string, tags []string, search,
|
||||
} else {
|
||||
//log.Printf("not refreshing %s", filepath)
|
||||
}
|
||||
}
|
||||
|
||||
root.MergeIn(root2)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user