Add some more functionality
This commit is contained in:
parent
e7b9ad2c29
commit
30978b9c94
21
task.go
21
task.go
@ -48,7 +48,8 @@ type Task struct {
|
|||||||
// Contexts, Projects, Tags
|
// Contexts, Projects, Tags
|
||||||
//
|
//
|
||||||
// For example:
|
// For example:
|
||||||
// "(A) 2013-07-23 Call Dad @Home @Phone +Family due:2013-07-31 customTag1:Important!"
|
//
|
||||||
|
// "(A) 2013-07-23 Call Dad @Home @Phone +Family due:2013-07-31 customTag1:Important!"
|
||||||
func (task Task) String() string {
|
func (task Task) String() string {
|
||||||
var text string
|
var text string
|
||||||
|
|
||||||
@ -270,3 +271,21 @@ func (task *Task) Due() time.Duration {
|
|||||||
}
|
}
|
||||||
return task.DueDate.Sub(time.Now())
|
return task.DueDate.Sub(time.Now())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (task *Task) HasContext(ctx string) bool {
|
||||||
|
for _, c := range task.Contexts {
|
||||||
|
if c == ctx {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (task *Task) HasProject(proj string) bool {
|
||||||
|
for _, p := range task.Projects {
|
||||||
|
if p == proj {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
13
todotxt.go
13
todotxt.go
@ -183,6 +183,19 @@ func (tasklist *TaskList) WriteToFilename(filename string) error {
|
|||||||
return ioutil.WriteFile(filename, []byte(tasklist.String()), 0640)
|
return ioutil.WriteFile(filename, []byte(tasklist.String()), 0640)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (tasklist *TaskList) ArchiveTaskToFile(task Task, filename string) error {
|
||||||
|
if err := tasklist.RemoveTask(task); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
f, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0600)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
_, err = f.WriteString(task.String() + "\n")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// LoadFromFile loads and returns a TaskList from *os.File.
|
// LoadFromFile loads and returns a TaskList from *os.File.
|
||||||
//
|
//
|
||||||
// Using *os.File instead of a filename allows to also use os.Stdin.
|
// Using *os.File instead of a filename allows to also use os.Stdin.
|
||||||
|
Loading…
Reference in New Issue
Block a user