Documentation
¶
Overview ¶
Package habit implements a habit tracker and accompanying CLI.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Now = time.Now
Now provides a seam to allow the time.Now() function to be overriden for testing.
Functions ¶
func Main ¶
func Main() int
Main is the driver for the CLI. It reads command-line arguments and allows a new Habit to be added, an existing Habit to be updated, or a summary of all stored Habits to be printed. It returns an exit code where 0 means the command was successful and anything other than 0 means the command failed.
func OpenStore ¶
OpenStore opens the store file at the given path and returns a store initialized with the key-value data contained in the file. An error is returned if there is a problem opening the store file or decoding its data.
func WithOutput ¶
WithOutput accepts an io.Writer and returns an option that wires the io.Writer to a Tracker.
Types ¶
type Habit ¶
type Habit struct { // Name is the name of the habit. Name string // CurrentStreak is the number of days in a row this habit has // been performed. CurrentStreak int // LastDone is the timestamp when the habit was last done. LastDone time.Time }
A Habit represents a habit that can be tracked.
type Tracker ¶
type Tracker struct {
// contains filtered or unexported fields
}
A Tracker provides habit-tracking and summarization logic.
func NewTracker ¶
NewTracker accepts an optional list of options and returns a Tracker initialized with these options. If no options are provided, the Tracker stores its data to a local file "habit.store" and writes to stdout. An error is returned if there is a problem opening the data store or if any of the opts returns an error.
func (Tracker) PrintSummary ¶
func (t Tracker) PrintSummary()
PrintSummary writes a summary of tracked Habits to the given Tracker's output.