move pttodo-cli up from /cmd/
This commit is contained in:
40
cmd/add.go
Normal file
40
cmd/add.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"gogs.inhome.blapointe.com/bel/pttodo/pttodo"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
func add(config *config) error {
|
||||
if config.add == "" {
|
||||
return nil
|
||||
}
|
||||
v := pttodo.Todo{
|
||||
Todo: config.add,
|
||||
Schedule: pttodo.Schedule(config.addSchedule),
|
||||
Tags: config.addTags,
|
||||
}
|
||||
newTarget, err := _add(config.targets, v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
config.targets = append(config.targets, newTarget)
|
||||
return nil
|
||||
}
|
||||
|
||||
func _add(filepaths []string, todo pttodo.Todo) (string, error) {
|
||||
target := filepaths[0] + ".todo." + uuid.New().String()
|
||||
|
||||
c, err := yaml.Marshal([]pttodo.Todo{todo})
|
||||
if err != nil {
|
||||
return "", err
|
||||
} else if err := ioutil.WriteFile(target, c, os.ModePerm); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return target, nil
|
||||
}
|
||||
Reference in New Issue
Block a user