Documentation ¶
Index ¶
- Constants
- func CLI(cli interface{}, name, description string, options ...kong.Option) *kong.Context
- type Config
- func (c *Config) AddTask(t *Task) (err error)
- func (c *Config) Delete(ids []int, archiveFile bool) (err error)
- func (c *Config) DeleteTasks(tasks []*Task, archiveFile bool) (err error)
- func (c *Config) DoTask(task *Task, archive bool) error
- func (c *Config) DoTasks(tasks []*Task, archive bool) error
- func (c *Config) DoneTasks() (tasks []*Task, err error)
- func (c *Config) Donetxt() (*os.File, error)
- func (c *Config) Tasks() (tasks []*Task, err error)
- func (c *Config) Todotxt() (*os.File, error)
- func (c *Config) UpdateTask(t *Task) (err error)
- func (c *Config) UpdateTasks(tasks []*Task) (err error)
- type Env
- type Task
- func (t *Task) Description() string
- func (t *Task) GetTagValue(tag string) (string, bool)
- func (t *Task) MarkDone()
- func (t *Task) Position() int
- func (t *Task) Render(showPos, color bool) string
- func (t *Task) String() string
- func (t *Task) Style() termenv.Style
- func (t *Task) UpdateDescription(description string)
- func (t *Task) UpdateTag(key, newValue string) bool
Constants ¶
const (
// DateFormat The format used for dates on disk
DateFormat = "2006-01-02"
)
Variables ¶
This section is empty.
Functions ¶
func CLI ¶
CLI calls kong.Parse creating a *kong.Context. It handles the usage sub command, printing out the usage message and exiting if found. Example usage:
var CLI struct { godo.Env TaskNumbers bool `default:"true" help:"show tasks position in the file" short:"i"` } func main() { _ = godo.CLI(&CLI, "did", "See tasks in the archive file") cfg := godo.NewConfig(CLI.Env) ... }
Types ¶
type Config ¶
type Config struct {
Env
}
Config allows for interaction with the users TODOTXT files. Use NewConfig to create TODO Allow configuration of preserving priority on task completion
func (*Config) AddTask ¶
AddTask appends a Task to the todotxt, creating the file in Env.TODODir if it does not exist. Ignores any position value that might exist in t
func (*Config) Delete ¶
Delete remove tasks by position from either the todotxt or, if archiveFile is true, from the donetxt
func (*Config) DeleteTasks ¶
DeleteTasks removes the given tasks from either the todotxt or, if archiveFile is true, from the donetxt
func (*Config) Donetxt ¶
Donetxt provides a file handle to the users done.txt or an error. It creates the file in Env.TODODir if it does not exist. It is the callers' responsibility to close the file after use
func (*Config) Todotxt ¶
Todotxt provides a file handle to the users todotxt file or an error. It creates the file in Env.TODODir if it does not exist. It is the callers' responsibility to close the file after use
func (*Config) UpdateTask ¶
UpdateTask updates a task in position in the todotxt. Use UpdateTasks for efficient updates to multiple tasks. See UpdateTasks for more details
func (*Config) UpdateTasks ¶
UpdateTasks updates each task in the provided array in place in the todotxt This function is atomic. It steams tasks out to a temporary file and moves replaces the todotxt at the end.
type Env ¶
type Env struct { // PreserveLineNumbers leaves a blank line when a TODOTXT entry is deleted PreserveLineNumbers bool `env:"TODOTXT_PRESERVE_LINE_NUMBERS" hidden:"" default:"false"` // Verbose enables verbose log output Verbose bool `env:"TODOTXT_VERBOSE" hidden:"" default:"false"` // Plain disables color output Plain bool `env:"TODOTXT_PLAIN" hidden:"" default:"false"` // AutoArchive signifies completed todos should be moved to the archive file AutoArchive bool `env:"TODOTXT_AUTO_ARCHIVE" hidden:"" default:"false"` // Force disables confirmation messages Force bool `env:"TODOTXT_FORCE" hidden:"" default:"false"` // DateOnAdd means prepend the current date to a task when it's added DateOnAdd bool `env:"TODOTXT_DATE_ON_ADD" hidden:"" default:"false"` // Sh name of the todosh script, use in the usage message Sh string `env:"TODO_SH" hidden:""` // FullSh complete path to calling todosh script, use for invoking todosh FullSh string `env:"TODO_FULL_SH" hidden:""` // ConfigFile is the path to the users configuration file ConfigFile string `env:"TODOTXT_CFG_FILE" hidden:""` // TODODir is the directory containing the config file. Defaults to "./testdata/" for testing outside of the TODOTXT // runtime TODODir string `env:"TODO_DIR" hidden:"" default:"./testdata/" type:"existingdir"` }
Env is a kong compatible struct that can be included in a CLI configuration to account for the environment variables provided by todotxt. Use the CLI function to handle construction and usage message printing when the "usage" command is passed.
Note: TODODir is set to "./testdata/" by default to aid in testing during development, but the todotxt CLI sets this variable
type Task ¶
type Task struct { // The completion status of a Task. True if the task is marked as complete. Complete bool // The priority of the task. A to Z uppercase. Optional Priority string // The date the task was completed on. Format of DateFormat. Optional CompletionDate string // The date the task was created on. Format of DateFormat. Optional unless completion date is set CreationDate string // contains filtered or unexported fields }
Task represents a single entry of a TODOTXT. The description part is not directly exposed. Use UpdateDescription and Description instead.
func SortTasks ¶
SortTasks provides a default sorting for a slice of tasks. Tasks with a priority will be at the start of the slice beginning with "A"s. Matching priority will sort on position. All tasks without a priority will follow, sorted by position.
func (*Task) Description ¶
Description retrieves the currently set description as a string
func (*Task) GetTagValue ¶
GetTagValue returns a value of a tag and true if the tag is present in the description of a Task or an empty string false
func (*Task) MarkDone ¶
func (t *Task) MarkDone()
MarkDone sets Complete to true and sets the CompletionDate to today's date, if it is not already set
func (*Task) Render ¶
Render provides a default rendering including task number if showPos is true and colors if color is true
func (*Task) UpdateDescription ¶
UpdateDescription allows changes the description part of a Task