package main import ( "fmt" "io/ioutil" "os" "github.com/google/uuid" "gitea.inhome.blapointe.com/gogs/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, } return _add(config.Targets()[0], v) } func _add(filepath string, todo pttodo.Todo) error { target := fmt.Sprintf("%s.todo.%s", filepath, 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 nil }