Archived
add(taskwarrior): get exported taskwarrior tasks
This implementation uses a filter struct to create taskwarrior filters (like you would do in the command line) to export the filtered tasks into json which are parsed as go structs.
This commit is contained in:
1 parent
3a04085d3a
commit
6f27c0a4d9
4 files changed
+106
No files matched your search
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"gitea.yves-biener.de/yves-biener/gitwarrior/internal/gitea"
|
||||
"gitea.yves-biener.de/yves-biener/gitwarrior/internal/gitw"
|
||||
"gitea.yves-biener.de/yves-biener/gitwarrior/internal/taskwarrior"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -54,6 +55,30 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
var filter taskwarrior.Filter
|
||||
filter.IncludeProjects("notes")
|
||||
tasks, err := taskwarrior.GetTasks(filter)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
for _, task := range tasks {
|
||||
fmt.Printf("%#v\n", task)
|
||||
}
|
||||
fmt.Println("---")
|
||||
|
||||
filter.Reset()
|
||||
filter.IncludeIds(1, 2, 3)
|
||||
tasks, err = taskwarrior.GetTasks(filter)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
for _, task := range tasks {
|
||||
fmt.Printf("%#v\n", task)
|
||||
}
|
||||
fmt.Println("---")
|
||||
|
||||
// necessary configurations (see config file gitw.json)
|
||||
// - access code for gitea
|
||||
// - configuration for taskwarrior settings?
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package taskwarrior
|
||||
|
||||
import "fmt"
|
||||
|
||||
type Filter struct {
|
||||
filter []string
|
||||
}
|
||||
|
||||
func (f *Filter) Reset() {
|
||||
f.filter = nil
|
||||
}
|
||||
|
||||
func (f *Filter) IncludeProjects(projects ...string) {
|
||||
for _, project := range projects {
|
||||
f.filter = append(f.filter, fmt.Sprintf("project:%s", project))
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Filter) IncludeTags(tags ...string) {
|
||||
for _, tag := range tags {
|
||||
f.filter = append(f.filter, fmt.Sprintf("+%s", tag))
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Filter) ExcludeTags(tags ...string) {
|
||||
for _, tag := range tags {
|
||||
f.filter = append(f.filter, fmt.Sprintf("-%s", tag))
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Filter) IncludeIds(ids ...uint) {
|
||||
for _, id := range ids {
|
||||
f.filter = append(f.filter, fmt.Sprintf("%d", id))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
package taskwarrior
|
||||
@@ -1 +1,46 @@
|
||||
package taskwarrior
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
/// A task with an Id of 0 is either `completed` or `deleted` which is also
|
||||
/// mentioned in the Status field
|
||||
|
||||
type Task struct {
|
||||
Id uint
|
||||
Project string
|
||||
Tags []string
|
||||
Description string
|
||||
Annotations []Annotation
|
||||
Status string
|
||||
Due string
|
||||
Entry string
|
||||
Modified string
|
||||
End string
|
||||
Uuid string
|
||||
Urgency float32
|
||||
}
|
||||
|
||||
type Annotation struct {
|
||||
Description string
|
||||
Entry string
|
||||
}
|
||||
|
||||
func GetTasks(filter Filter) ([]Task, error) {
|
||||
filter.filter = append(filter.filter, "export")
|
||||
cmd := exec.Command("task", filter.filter...)
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var tasks []Task
|
||||
decoder := json.NewDecoder(bytes.NewBuffer(out))
|
||||
decoder.DisallowUnknownFields()
|
||||
if err = decoder.Decode(&tasks); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return tasks, nil
|
||||
}
|
||||
Reference in new issue
Block a user