klein

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2021 License: GPL-3.0 Imports: 15 Imported by: 0

README

klein

A CLI decision journal written in golang, with a focus on speed and convenience of use via the command line.

Install

Currently klein is only supported on Linux. You need to install golang on your Linux distro, and source the $GOBIN folder in your shell. By default, this folder is ~/go/bin.

Once that is done, just run the below command.

go get codeberg.org/xyank/klein/klein

Restart your shell, and you can now use the latest release of klein.

Usage

Here are commands with examples:

# View all decisions logged, whether you have reviewed them or not
klein

# View decisions that you haven't reviewed yet
klein status:pending

# View reviewed decisions
klein status:reviewed

# View decisions that have the tag "career"
klein +career

# Add a decision that you have made, with optional description and confidence
# and tagged with "health" and "milk"
# The confidence field here shows the confidence you have in the decision being
# correct and leading to positive outcomes in the long run, whether you can
# predict them or not
klein add "Write a golang decision journal application" description:"I want to \
          improve my decision making. The obvious thing to do then is to track my \
          decisions and review them. I also want to improve my golang skills. On the \
          other hand, I still have an unfinished project, and I haven't met my friends in \
          months." confidence:0.65 +career +technical

# The default confidence level is 0.50
klein add "I will buy milk this week" description:"I might make cookies this \
          week, but on the other hand I might want to stick to the diet I've been on"

# Use your text editor to modify decisions
klein edit 1

# Review a specific decision, stating that your decision wasn't a good idea, and why
# Giving a reason is optional
klein review 2 judgement:false reason:"I got a stomach bug. Not fun."

# You can re-review decisions
klein review 2 judgement:true reason:"The stomach bug may have been caused by \
          drinking expired orange juice, not because of the milk. Plus I didn't break my \
          diet, so it was a good decision to buy milk."

# Delete specific decisions using their IDs
klein delete 1 2

Documentation

Index

Constants

View Source
const (
	VERSION = "0.1.1"

	CMD_INIT    = "init"
	CMD_EDIT    = "edit"
	CMD_ADD     = "add"
	CMD_HELP    = "help"
	CMD_VERSION = "version"
	CMD_REVIEW  = "review"
	CMD_DELETE  = "delete"

	STATUS_PENDING  = "pending"  // to review
	STATUS_REVIEWED = "reviewed" // reviewed, may re-review later
	STATUS_DELETED  = "deleted"  // moved to deleted folder

	TABLE_MAX_WIDTH  = 160
	TABLE_COL_GAP    = 2
	ANSI_CODE_HEADER = 1 // Bold the header by default

	UUIDv4_LEN = 36

	// TODO After implementing status, rename this constant
	MAX_DECISIONS = 10000
)
View Source
const (
	HelpGeneral = `` /* 373-byte string literal not displayed */

	HelpVersion = `Usage: klein version
Prints semantic version of binary

Example:
$ klein version
v0.2.0
	`
	HelpAdd = `` /* 589-byte string literal not displayed */

	HelpEdit = `` /* 169-byte string literal not displayed */

	HelpDelete = `` /* 312-byte string literal not displayed */

	HelpReview = `` /* 352-byte string literal not displayed */

)

Variables

View Source
var NON_RESOLVED_STATUSES = []string{
	STATUS_PENDING,
	STATUS_REVIEWED,
}

Functions

func AdjustCell

func AdjustCell(text string, width int) string

format cell text to conform to the specified width

func CommandAdd

func CommandAdd(conf Config, cmdLine CmdLine) error

func CommandDashboard

func CommandDashboard(conf Config, cmdLine CmdLine) error

Print a tree style dashboard of unresolved decisions Default command

func CommandDelete

func CommandDelete(conf Config, cmdLine CmdLine) error

func CommandEdit

func CommandEdit(conf Config, cmdLine CmdLine) error

Edit a decision using an editor

func CommandHelp added in v1.0.0

func CommandHelp(args []string) error

func CommandInit

func CommandInit(conf Config, cmdLine CmdLine) error

Create data dir and init git repository

func CommandReview

func CommandReview(conf Config, cmdLine CmdLine) error

func CommandVersion added in v1.0.0

func CommandVersion() error

func DeduplicateStrings

func DeduplicateStrings(strings []string) []string

func EnsureRepoExists

func EnsureRepoExists(repoPath string) error

func GetValidConfidenceValue

func GetValidConfidenceValue(text string) (value float64, err error)

func GetValidJudgementValue

func GetValidJudgementValue(text string) (string, error)

func HelpSwitch added in v1.0.0

func HelpSwitch(args []string) error

func IsValidConfidenceValue

func IsValidConfidenceValue(c float64) bool

func IsValidStatus

func IsValidStatus(s string) error

func IsValidUUIDv4String

func IsValidUUIDv4String(str string) bool

func MaxInt

func MaxInt(vals []int) (index int, max int)

func MustEditBytes

func MustEditBytes(data []byte, extension string) ([]byte, error)

func MustGetTermSize

func MustGetTermSize() (int, int, error)

func MustGetUUID4String

func MustGetUUID4String() string

func RunCmd

func RunCmd(name string, args ...string) error

func StrSliceContains

func StrSliceContains(haystack []string, needle string) bool

func StrSliceContainsAll

func StrSliceContainsAll(subset, superset []string) bool

Return true iff superset contains entire subset

func SumInts

func SumInts(vals ...int) int

Types

type CmdLine

type CmdLine struct {
	Cmd         string
	IDs         []int
	Tags        []string
	Confidence  float64
	Text        string
	Judgement   string
	Reason      string
	Review      string
	Status      string
	Description string
}

Struct of all possible elements in a command line (after the command itself)

func ParseCmdLine

func ParseCmdLine(args ...string) (CmdLine, error)

type Config

type Config struct {
	// Path to git repository (not the .git/ directory but the work tree) used for yaml files
	Repo string

	// Path to persistent storage of ephemeral IDs
	IDsFile string
}

func NewConfig

func NewConfig() Config

type Decision

type Decision struct {
	// not stored in file -- rather filename and directory
	UUID   string `yaml:"-"`          // yaml ignores this field
	Status string `yaml:",omitempty"` // show status when editing via edit command

	// is new or has changed. Need to write to disk.
	WritePending bool `yaml:"-"`

	// Mark decision for deletion
	Deleted bool `yaml:"-"`

	// ephemeral
	ID int `yaml:"-"`

	Decision    string
	Description string `yaml:",omitempty"`
	Confidence  float64
	Tags        []string
	Reason      string `yaml:",omitempty"`

	// Use string so that "false" judgements are also written to reviewed decisions
	Judgement string `yaml:",omitempty"`
	Review    string `yaml:",omitempty"`

	Created  time.Time
	Reviewed time.Time `yaml:",omitempty"`
	// contains filtered or unexported fields
}

Decisions are statements that are "backed" (that is, associated with) predictions. Computationally this means that it contains a list of predictions.

func UnmarshalDecision

func UnmarshalDecision(path string, finfo os.FileInfo, ids IdsMap, status string) (Decision, error)

Unmarshall a Decision, given a YAML file path

func (*Decision) DeleteCopies

func (d *Decision) DeleteCopies(repoPath string) error

func (*Decision) NormaliseFields

func (d *Decision) NormaliseFields()

Mutate and sort fields to a common format Makes git diffs more useful

func (*Decision) SaveToDisk

func (d *Decision) SaveToDisk(repoPath string) error

func (*Decision) ValidateFields

func (d *Decision) ValidateFields() error

TODO Add more validation for fields if necessary here

type DecisionSet

type DecisionSet struct {
	Decisions []*Decision
	// contains filtered or unexported fields
}

func NewDecisionSet

func NewDecisionSet(repoPath, idsFilePath string, opts ...DecisionSetOpt) (*DecisionSet, error)

func (*DecisionSet) DisplayDashboard

func (ds *DecisionSet) DisplayDashboard() error

func (*DecisionSet) FilteredDecisions

func (ds *DecisionSet) FilteredDecisions() []Decision

func (*DecisionSet) LoadDecision

func (ds *DecisionSet) LoadDecision(decision Decision) Decision

Add a decision to DecisionSet, keeping in mind the DecisionSet's state This means this function adjusts the ID of the decision (only if necessary), adds a UUID if none exists, and adds the Created time if it isn't there either

func (*DecisionSet) MustUpdateDecision

func (ds *DecisionSet) MustUpdateDecision(d Decision) error

replace decision in set with the new one

func (*DecisionSet) SavePendingChanges

func (ds *DecisionSet) SavePendingChanges() error

save pending changes to disk

type DecisionSetOpt

type DecisionSetOpt func(opts *DecisionSetOpts)

func WithIDs

func WithIDs(ids ...int) DecisionSetOpt

func WithStatuses

func WithStatuses(statuses ...string) DecisionSetOpt

func WithTags

func WithTags(tags ...string) DecisionSetOpt

type DecisionSetOpts

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

type IdsMap

type IdsMap map[string]int

persistent DB of UUID -> ID Ensures that decision have a persistent ID local to the machine for their lifetime Ensures the correct decision is targeted between operations

func LoadIds

func LoadIds(idsFilePath string) (IdsMap, error)

func (*IdsMap) SaveIds

func (ids *IdsMap) SaveIds(idsFilePath string) error

type RowStyle

type RowStyle struct {
	// ansi mode
	Mode int
}

type Table

type Table struct {
	Header    []string
	Rows      [][]string
	RowStyles []RowStyle
	Width     int
}

func NewTable

func NewTable(width int, header ...string) *Table

func (*Table) AddRow

func (t *Table) AddRow(row []string, style RowStyle) error

func (*Table) Render

func (t *Table) Render() (err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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