chronolib

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 1, 2019 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const ChronoAppConf = "chrono"

ChronoAppConf is the name of the app's data directory

View Source
const ChronoConfDirEnvName = "CHRONO_CONFIG_DIR"

ChronoConfDirEnvName is name of the environment variable used to manually set the config directory

View Source
const ChronoConfigFilename = "config.toml"

ChronoConfigFilename is the config's expected filename

Variables

View Source
var NoColor = false

NoColor if set to false will no color any output with ANSI color codes

Functions

func CheckTags

func CheckTags(tags []string) error

CheckTags returns nil if all tags are valid, otherwise it returns a error

func CompileKeyword added in v1.1.0

func CompileKeyword(target string) (time.Time, error)

CompileKeyword converts a given string containing a keyword into its associated time.Time

func ContainsMoreThanOneBooleanFlag

func ContainsMoreThanOneBooleanFlag(flags ...bool) bool

ContainsMoreThanOneBooleanFlag is a helper method for checking if more than one boolean is true

func EditFile

func EditFile(editor string, fpath string)

EditFile opens a file in an external text editor

func EnsureConfigDirExists

func EnsureConfigDirExists(configDirectory string) error

EnsureConfigDirExists makes sure the configDirectory path exists

func FilterFramesByTimespan

func FilterFramesByTimespan(start time.Time, end time.Time, frames *[]Frame, noCheck bool, tags []string) map[time.Time][]Frame

FilterFramesByTimespan returns only frames that are in the given timespan

func FormatCancelMessage

func FormatCancelMessage(currentFrame CurrentFrame) string

FormatCancelMessage shows a message if the current state is stopped but not saved

func FormatDateHeader

func FormatDateHeader(date time.Time) string

FormatDateHeader returns a time formated with Tuesday 2 January 2006

func FormatEditFrameMessage

func FormatEditFrameMessage(frame Frame) string

FormatEditFrameMessage returns the output when a frame is modified

func FormatFrameDelete

func FormatFrameDelete(frame Frame) string

FormatFrameDelete shows confirmation messasge to delete a frame

func FormatFrameDescribe

func FormatFrameDescribe(frame Frame) string

FormatFrameDescribe shows information about a frame in a consise manner

func FormatFrameLine

func FormatFrameLine(frame Frame) string

FormatFrameLine returns a frame line (all the metadata about a frame except for its notes)

func FormatNewFrameMessage

func FormatNewFrameMessage(frame Frame) string

FormatNewFrameMessage returns the output when a new frame is created

func FormatNoFramesMessage

func FormatNoFramesMessage() string

FormatNoFramesMessage returns the output when there is no current frame

func FormatNoNotesMessage

func FormatNoNotesMessage() string

FormatNoNotesMessage returns the output if there are no notes in the current frame

func FormatNoProjectMessage

func FormatNoProjectMessage() string

FormatNoProjectMessage returns the output when there is no current frame

func FormatNoteLine

func FormatNoteLine(note string) string

FormatNoteLine formats a single frame note

func FormatNoteShowLine

func FormatNoteShowLine(index int, note string) string

FormatNoteShowLine formats a single frame note for the notes show command

func FormatReportDuration

func FormatReportDuration(timeStart time.Time) string

FormatReportDuration returns the duration currently being viewed in the report command

func FormatReportDurationDate

func FormatReportDurationDate(t time.Time) string

FormatReportDurationDate returns the date using format Mon 02 January 2006

func FormatReportProjectTagTotal

func FormatReportProjectTagTotal(tag string, total time.Duration) string

FormatReportProjectTagTotal return the total time spent on a tag for a project

func FormatReportProjectTotal

func FormatReportProjectTotal(project string, total time.Duration) string

FormatReportProjectTotal returns the total time spent on a project

func FormatStartCurrentFrame

func FormatStartCurrentFrame(currentFrame CurrentFrame) string

FormatStartCurrentFrame returns the output when a new frame is created

func FormatStartError

func FormatStartError(frame CurrentFrame) string

FormatStartError returns a message formated red that says a project is already started

func FormatStartFrame

func FormatStartFrame(frame Frame) string

FormatStartFrame returns the output when a new frame is created

func FormatStatusFrameMessage

func FormatStatusFrameMessage(frame Frame) string

FormatStatusFrameMessage returns the output the current status for active frame

func FormatStopFrameMessage

func FormatStopFrameMessage(frame Frame) string

FormatStopFrameMessage returns the output when time tracking for a frame is stopped

func FormatTagNotValid added in v1.1.0

func FormatTagNotValid() string

FormatTagNotValid returns a message when a time string was unable to be parsed

func FormatTags

func FormatTags(tags []string) string

FormatTags joins tags together and color them blue

func FormatTimeStringNotValid

func FormatTimeStringNotValid() string

FormatTimeStringNotValid returns a message when a time string was unable to be parsed

func FramesEqual

func FramesEqual(f1 Frame, f2 Frame) bool

FramesEqual check if frames are equal

func GetAppFilePath

func GetAppFilePath(fileName string, customConfDir string) string

GetAppFilePath returns a file's path in the config directory through either an environment variable or the default path

func GetCorrectConfigDirectory

func GetCorrectConfigDirectory(customConfigPath string) string

GetCorrectConfigDirectory returns the correct config path where customConfigPath > Env Variable > Default value

func GetEditorEnv

func GetEditorEnv() string

GetEditorEnv returns the preferred text editor's binary name

func GetShortHex

func GetShortHex(sha string) string

GetShortHex returns the first six characters from a hex encoded SHA

func GetTimeElapsed

func GetTimeElapsed(dateStart, dateEnd time.Time) (int, int, int)

GetTimeElapsed calculates the delta between two Times and returns the hours, minutes, and seconds for that delta

func GetTimeElapsedForDuration

func GetTimeElapsedForDuration(delta time.Duration) (int, int, int)

GetTimeElapsedForDuration returns the hours, minutes, seconds for a given duration

func GetTimespanForMonth

func GetTimespanForMonth() (time.Time, time.Time)

GetTimespanForMonth returns the start and end date for the current month

func GetTimespanForToday

func GetTimespanForToday() (time.Time, time.Time)

GetTimespanForToday returns the the start date and end date of today

func GetTimespanForWeek

func GetTimespanForWeek() (time.Time, time.Time)

GetTimespanForWeek returns the start and end date for the current week

func GetTimespanForYear

func GetTimespanForYear() (time.Time, time.Time)

GetTimespanForYear returns the start and end date for the current year

func GetTimespanForYesterday added in v1.1.0

func GetTimespanForYesterday() (time.Time, time.Time)

GetTimespanForYesterday returns the start and end date for yesterday

func HasSameDate

func HasSameDate(t1 *time.Time, t2 *time.Time) bool

HasSameDate checks if the date (month, year, day) are the same

func IsFrameInTimespan

func IsFrameInTimespan(frame Frame, start time.Time, end time.Time) bool

IsFrameInTimespan checks if a frame's start and end time are both in the given timespan

func IsKeyword added in v1.1.0

func IsKeyword(target string) bool

IsKeyword checks if given target string is a valid keyword

func IsTimeInTimespan

func IsTimeInTimespan(point time.Time, start time.Time, end time.Time) bool

IsTimeInTimespan checks if point is inside the timespan between start and end

func IsTimespanNegative

func IsTimespanNegative(start time.Time, end time.Time) bool

IsTimespanNegative returns true if a timespan has a negative amount of time, false otherwise

func NormalizeDate

func NormalizeDate(precise time.Time) time.Time

NormalizeDate strips hours, minutes, and seconds from a given time

func NormalizeTags

func NormalizeTags(tags []string) []string

NormalizeTags tags (trims the prefix, lowercases, and replaces spaces with dashes)

func OrganizeFrameByTime

func OrganizeFrameByTime(frames *[]Frame) map[time.Time][]Frame

OrganizeFrameByTime returns a map of frames where the key is the date of the frame

func PrettyDate

func PrettyDate(t *time.Time) string

PrettyDate returns the date using format 2 January 2006 15:04

func RenderCurrentFrameStatus

func RenderCurrentFrameStatus(currentFrame CurrentFrame, format string) string

RenderCurrentFrameStatus returns the status output using Go template string

func RenderStatusFormatString

func RenderStatusFormatString(frame Frame, format string) string

RenderStatusFormatString returns the status output using Go template string

func SaveFrames

func SaveFrames(config ChronoConfig, frames Frames) error

SaveFrames writes frames

func SaveState

func SaveState(config ChronoConfig, state State) error

SaveState writes the state to the file

func SortFramesByDate

func SortFramesByDate(frames []Frame)

SortFramesByDate sorts frame by its start date

func SortTimeMapKeys

func SortTimeMapKeys(timemap *map[time.Time][]Frame) []time.Time

SortTimeMapKeys sorts a timemap by its key (a time.Time)

func StringInSlice

func StringInSlice(target string, list []string) bool

StringInSlice checks if a string is present in a slice

Types

type ChronoConfig

type ChronoConfig struct {
	ConfigDir     string
	StorageType   string
	GeneralConfig chronoGeneralConfig
}

ChronoConfig contains the currently used config dir path as well as any configuration options stored in config.toml

func GetConfig

func GetConfig(configDirectory string) ChronoConfig

GetConfig loads the a confi file if it exists and returns a ChronoConfig struct

type CurrentFrame

type CurrentFrame struct {
	Project   string
	StartedAt time.Time
	UpdatedAt time.Time
	Tags      []string
	Notes     []string
}

CurrentFrame contains data for the current frame

type Data

type Data struct {
	Frames []Frame
}

Data is a wrapper for frames

type ErrFileDoesNotExist

type ErrFileDoesNotExist struct {
	// contains filtered or unexported fields
}

ErrFileDoesNotExist represents when a file doesn't exist on the file system

func NewErrFileDoesNotExist

func NewErrFileDoesNotExist(message string) *ErrFileDoesNotExist

NewErrFileDoesNotExist creates a new ErrFileDoesNotExist

func (*ErrFileDoesNotExist) Error

func (e *ErrFileDoesNotExist) Error() string

Error returns the error message

type ErrFrameNotFound

type ErrFrameNotFound struct {
	// contains filtered or unexported fields
}

ErrFrameNotFound means a frame wasn't found

func NewErrFrameNotFound

func NewErrFrameNotFound(message string) *ErrFrameNotFound

NewErrFrameNotFound creates a new ErrFrameNotFound

func (*ErrFrameNotFound) Error

func (e *ErrFrameNotFound) Error() string

Error returns the error message

type ErrFramesFileDoesNotExist

type ErrFramesFileDoesNotExist struct {
	// contains filtered or unexported fields
}

ErrFramesFileDoesNotExist represents when a file doesn't exist on the file system

func NewErrFramesFileDoesNotExist

func NewErrFramesFileDoesNotExist(message string) *ErrFramesFileDoesNotExist

NewErrFramesFileDoesNotExist creates a new ErrFileDoesNotExist

func (*ErrFramesFileDoesNotExist) Error

func (e *ErrFramesFileDoesNotExist) Error() string

Error returns the error message

type ErrStateFileDoesNotExist

type ErrStateFileDoesNotExist struct {
	// contains filtered or unexported fields
}

ErrStateFileDoesNotExist represents when a file doesn't exist on the file system

func (*ErrStateFileDoesNotExist) Error

func (e *ErrStateFileDoesNotExist) Error() string

Error returns the error message

type Frame

type Frame struct {
	UUID      string
	Project   string
	StartedAt time.Time
	EndedAt   time.Time
	UpdatedAt time.Time
	Tags      []string
	Notes     []string
}

Frame is a timespan containing some metadata

func ConvertSimpleFrameToFrame

func ConvertSimpleFrameToFrame(uuid string, rawFrame SimpleFrame) (Frame, error)

ConvertSimpleFrameToFrame converts a raw frame back to a frame

func FilterFrames

func FilterFrames(frames *[]Frame, filterOptions FrameFilterOptions) []Frame

FilterFrames filters out a list of frames based on the given FrameFilterOptions

func GetFrameByShortHex

func GetFrameByShortHex(frames []Frame, hex string) (int, Frame, error)

GetFrameByShortHex gets a frame using the short form of its UUID

type FrameDeleteOptions

type FrameDeleteOptions struct {
	Target string
}

FrameDeleteOptions contains data needed to remove a frame

type FrameFilterOptions

type FrameFilterOptions struct {
	TimespanFilter TimespanFilterOptions
	Tags           []string
	Projects       []string
}

FrameFilterOptions contains filtering data for retrieving frames. An empty object means no filtering

type FrameGetOptions

type FrameGetOptions struct {
	Target string
}

FrameGetOptions contains filtering information needed to find a single Frame

type FrameStorage

type FrameStorage interface {
	All(filterOptions FrameFilterOptions) ([]Frame, error)
	Add(frame Frame) (Frame, error)
	Get(getOptions FrameGetOptions) (Frame, error)
	Delete(deleteOptions FrameDeleteOptions) (Frame, error)
	Update(frame Frame) (Frame, error)
	Projects() ([]string, error)
	Tags() ([]string, error)
}

FrameStorage is an interface for a frame storage backend

type Frames

type Frames struct {
	Frames []Frame
}

Frames contains recordered frames

func GetFrames

func GetFrames(config ChronoConfig) (Frames, error)

GetFrames writes frames

func (*Frames) Add

func (s *Frames) Add(frame Frame)

Add a new frame to the frames list

func (*Frames) All

func (s *Frames) All() []Frame

All retrieves all frames

func (*Frames) Delete

func (s *Frames) Delete(targetFrame Frame)

Delete a frame from the frames list, matched by its UUID

func (*Frames) Filter

func (s *Frames) Filter(filterOptions FrameFilterOptions) []Frame

Filter retrieves frames based on filter options

func (*Frames) GetByIndex

func (s *Frames) GetByIndex(index int) (Frame, bool)

GetByIndex retrieves a frame by its index

func (*Frames) GetByUUID

func (s *Frames) GetByUUID(id string) (Frame, bool)

GetByUUID retrieves a frame by its uuid

func (*Frames) GetFrameIndex added in v1.1.0

func (s *Frames) GetFrameIndex(target Frame) int

func (*Frames) Projects

func (s *Frames) Projects() []string

Projects returns a list of all unique project names found in all frames

func (*Frames) Tags

func (s *Frames) Tags() []string

Tags returns a list of all unique tags found in all frames

func (*Frames) Update

func (s *Frames) Update(target Frame)

Update a frame in the frames list, matched by its UUID

type FramesRepo

type FramesRepo interface {
	Load() (Frames, error)
	Save(frames *Frames) error
}

FramesRepo is an interface for loading/saving frames

type GithubLatestRelease

type GithubLatestRelease struct {
	URL             string    `json:"url"`
	HTMLURL         string    `json:"html_url"`
	AssetsURL       string    `json:"assets_url"`
	UploadURL       string    `json:"upload_url"`
	TarballURL      string    `json:"tarball_url"`
	ZipballURL      string    `json:"zipball_url"`
	ID              int       `json:"id"`
	NodeID          string    `json:"node_id"`
	TagName         string    `json:"tag_name"`
	TargetCommitish string    `json:"target_commitish"`
	Name            string    `json:"name"`
	Body            string    `json:"body"`
	Draft           bool      `json:"draft"`
	Prerelease      bool      `json:"prerelease"`
	CreatedAt       time.Time `json:"created_at"`
	PublishedAt     time.Time `json:"published_at"`
	Author          struct {
		Login             string `json:"login"`
		ID                int    `json:"id"`
		NodeID            string `json:"node_id"`
		AvatarURL         string `json:"avatar_url"`
		GravatarID        string `json:"gravatar_id"`
		URL               string `json:"url"`
		HTMLURL           string `json:"html_url"`
		FollowersURL      string `json:"followers_url"`
		FollowingURL      string `json:"following_url"`
		GistsURL          string `json:"gists_url"`
		StarredURL        string `json:"starred_url"`
		SubscriptionsURL  string `json:"subscriptions_url"`
		OrganizationsURL  string `json:"organizations_url"`
		ReposURL          string `json:"repos_url"`
		EventsURL         string `json:"events_url"`
		ReceivedEventsURL string `json:"received_events_url"`
		Type              string `json:"type"`
		SiteAdmin         bool   `json:"site_admin"`
	} `json:"author"`
	Assets []struct {
		URL                string    `json:"url"`
		BrowserDownloadURL string    `json:"browser_download_url"`
		ID                 int       `json:"id"`
		NodeID             string    `json:"node_id"`
		Name               string    `json:"name"`
		Label              string    `json:"label"`
		State              string    `json:"state"`
		ContentType        string    `json:"content_type"`
		Size               int       `json:"size"`
		DownloadCount      int       `json:"download_count"`
		CreatedAt          time.Time `json:"created_at"`
		UpdatedAt          time.Time `json:"updated_at"`
		Uploader           struct {
			Login             string `json:"login"`
			ID                int    `json:"id"`
			NodeID            string `json:"node_id"`
			AvatarURL         string `json:"avatar_url"`
			GravatarID        string `json:"gravatar_id"`
			URL               string `json:"url"`
			HTMLURL           string `json:"html_url"`
			FollowersURL      string `json:"followers_url"`
			FollowingURL      string `json:"following_url"`
			GistsURL          string `json:"gists_url"`
			StarredURL        string `json:"starred_url"`
			SubscriptionsURL  string `json:"subscriptions_url"`
			OrganizationsURL  string `json:"organizations_url"`
			ReposURL          string `json:"repos_url"`
			EventsURL         string `json:"events_url"`
			ReceivedEventsURL string `json:"received_events_url"`
			Type              string `json:"type"`
			SiteAdmin         bool   `json:"site_admin"`
		} `json:"uploader"`
	} `json:"assets"`
}

GithubLatestRelease represents the data returned from the releases/latest endpoint. Autogenerated

type JSONFramesRepo

type JSONFramesRepo struct {
	// contains filtered or unexported fields
}

JSONFramesRepo stores state in the JSON format

func (JSONFramesRepo) Load

func (s JSONFramesRepo) Load() (Frames, error)

Load frames stored in the JSON format

func (JSONFramesRepo) Save

func (s JSONFramesRepo) Save(f *Frames) error

Save writes frames using the JSON format

type JSONStateRepo

type JSONStateRepo struct {
	// contains filtered or unexported fields
}

JSONStateRepo retrieves state in msgpack format

func (JSONStateRepo) Load

func (s JSONStateRepo) Load() (State, error)

Load reads the state

func (JSONStateRepo) Save

func (s JSONStateRepo) Save(state State) error

Save writes the state to the current file

type MsgpackFramesRepo

type MsgpackFramesRepo struct {
	// contains filtered or unexported fields
}

MsgpackFramesRepo retrieves state in msgpack format

func (MsgpackFramesRepo) Load

func (s MsgpackFramesRepo) Load() (Frames, error)

Load retrieves frames from the msgpack format

func (MsgpackFramesRepo) Save

func (s MsgpackFramesRepo) Save(f *Frames) error

Save writes frames using the msgpack format

type MsgpackStateRepo

type MsgpackStateRepo struct {
	// contains filtered or unexported fields
}

MsgpackStateRepo retrieves state in msgpack format

func (MsgpackStateRepo) Load

func (s MsgpackStateRepo) Load() (State, error)

Load reads the state

func (MsgpackStateRepo) Save

func (s MsgpackStateRepo) Save(state State) error

Save writes the state to the current file

type SimpleFrame

type SimpleFrame struct {
	Project   string
	StartedAt string
	EndedAt   string
	Tags      []string
	Notes     []string
}

SimpleFrame is used for converting to and from JSON

func ConvertFrameToSimpleFrame

func ConvertFrameToSimpleFrame(frame Frame) SimpleFrame

ConvertFrameToSimpleFrame converts a frame to a raw frame

type State

type State struct {
	CurrentFrame CurrentFrame
}

State contains the CurrentFrame and provides methods for interacting with it

func GetState

func GetState(config ChronoConfig) (State, error)

GetState retrieves the state

func (*State) Clear

func (s *State) Clear()

Clear the CurrentFrame from the state

func (*State) Get

func (s *State) Get() CurrentFrame

Get retreives the CurrentFrame from the State

func (*State) IsEmpty

func (s *State) IsEmpty() bool

IsEmpty checks if the CurrentFrame is empty

func (*State) ToFrame

func (s *State) ToFrame(end time.Time) Frame

ToFrame converts the CurrentFrame to a Frame by adding a UUID and end time

func (*State) Update

func (s *State) Update(CurrentFrame CurrentFrame)

Update the CurrentFrame

type StateRepo

type StateRepo interface {
	Load() (State, error)
	Save(state State) error
}

StateRepo is an interface for retieving current state

type StateStorage

type StateStorage interface {
	Get() (Frame, error)
	Update(frame Frame) (Frame, error)
	Clear() (Frame, error)
}

StateStorage is an interface for the current frame storage backend

type TimespanFilterOptions

type TimespanFilterOptions struct {
	Start time.Time
	End   time.Time
}

TimespanFilterOptions contains a start and end date to filter frames by

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL