Documentation
¶
Index ¶
- Constants
- Variables
- func CLI(cli interface{}, name, description string, options ...kong.Option) *kong.Context
- func InitContext(args []string, cli interface{}, options ...kong.Option) (*kong.Context, error)
- 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 ErrParse
- type Task
- func (t *Task) Complete() bool
- func (t *Task) CompletionDate() time.Time
- func (t *Task) Context() string
- func (t *Task) CreationDate() time.Time
- func (t *Task) Description() string
- func (t *Task) GetTagValue(tag string) (string, bool)
- func (t *Task) Position() int
- func (t *Task) Priority() string
- func (t *Task) Project() string
- func (t *Task) Render(showPos, color bool) string
- func (t *Task) SetComplete(complete bool)
- func (t *Task) SetCreationDate(cd time.Time)
- func (t *Task) SetPriority(p string) error
- func (t *Task) SetTag(key, newValue string)
- func (t *Task) String() string
- func (t *Task) Style() termenv.Style
- func (t *Task) UpdateCompletionDate(cd time.Time)
- 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 ¶
var ErrInvalidPriority = errors.New("priority must be a single uppercase letter")
var ErrUsageOnly = errors.New("usage output only")
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)
...
}
func InitContext ¶
InitContext calls kong.Parse creating a *kong.Context. It handles the "usage" sub command and returns ErrUsageOnly when invoked. User errors are returned as ErrParse and all other errors as kong presents them. This allows more control than CLI. Generally, CLI should be used
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 {
// contains filtered or unexported fields
}
Task represents a single entry of a TODOTXT.
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) CompletionDate ¶
CompletionDate gets the completion data or returns a 0 time if none set
func (*Task) CreationDate ¶
CreationDate gets the creation date or returns a 0 time if none set
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) Render ¶
Render provides a default rendering including task number if showPos is true and colors if color is true
func (*Task) SetComplete ¶
SetComplete sets completion status and update the completionDate if it is valid to do so. If the current status matches the complete argument SetComplete does nothing
func (*Task) SetCreationDate ¶
SetCreationDate sets the creation date if valid to do so. If set to prior to a set completion date it will do nothing
func (*Task) SetPriority ¶
func (*Task) SetTag ¶
SetTag updates the value of a tag in the description if found, or appends it to the end if not.
func (*Task) UpdateCompletionDate ¶
UpdateCompletionDate sets the completion date if it is valid to do so. Otherwise, does nothing It will set time to any value provided, as long as it is after the creation date
func (*Task) UpdateDescription ¶
UpdateDescription allows changes the description part of a Task