core

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2018 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Version is the current version of dnote
	Version = "0.2.1"

	// TimestampFilename is the name of the file containing upgrade info
	TimestampFilename = "timestamps"
	// DnoteDirName is the name of the directory containing dnote files
	DnoteDirName       = ".dnote"
	ConfigFilename     = "dnoterc"
	DnoteFilename      = "dnote"
	ActionFilename     = "actions"
	TmpContentFilename = "DNOTE_TMPCONTENT"
)

Variables

View Source
var (
	ActionAddNote    = "add_note"
	ActionRemoveNote = "remove_note"
	ActionEditNote   = "edit_note"
	ActionAddBook    = "add_book"
	ActionRemoveBook = "remove_book"
)

Functions

func ClearActionLog

func ClearActionLog(ctx infra.DnoteCtx) error

func FilterNotes

func FilterNotes(notes []infra.Note, testFunc func(infra.Note) bool) []infra.Note

func GetActionPath

func GetActionPath(ctx infra.DnoteCtx) string

GetActionPath returns the path to the file containing user actions

func GetConfigPath

func GetConfigPath(ctx infra.DnoteCtx) string

GetConfigPath returns the path to the dnote config file

func GetDnote

func GetDnote(ctx infra.DnoteCtx) (infra.Dnote, error)

GetDnote reads and parses the dnote

func GetDnotePath

func GetDnotePath(ctx infra.DnoteCtx) string

GetDnotePath returns the path to the dnote file

func GetDnoteTmpContentPath

func GetDnoteTmpContentPath(ctx infra.DnoteCtx) string

GetDnoteTmpContentPath returns the path to the temporary file containing content being added or edited

func GetEditorInput

func GetEditorInput(ctx infra.DnoteCtx, fpath string, content *string) error

GetEditorInput gets the user input by launching a text editor and waiting for it to exit

func GetTimestampPath

func GetTimestampPath(ctx infra.DnoteCtx) string

GetTimestampPath returns the path to the file containing dnote upgrade information

func GetUpdatedBook

func GetUpdatedBook(book infra.Book, notes []infra.Note) infra.Book

func InitActionFile

func InitActionFile(ctx infra.DnoteCtx) error

InitActionFile populates action file if it does not exist

func InitConfigFile

func InitConfigFile(ctx infra.DnoteCtx) error

InitConfigFile populates a new config file if it does not exist yet

func InitDnoteDir

func InitDnoteDir(ctx infra.DnoteCtx) error

InitDnoteDir initializes dnote directory if it does not exist yet

func InitDnoteFile

func InitDnoteFile(ctx infra.DnoteCtx) error

InitDnoteFile creates an empty dnote file

func InitTimestampFile

func InitTimestampFile(ctx infra.DnoteCtx) error

InitTimestampFile creates an empty dnote upgrade file

func IsFreshInstall

func IsFreshInstall(ctx infra.DnoteCtx) (bool, error)

IsFreshInstall checks if the dnote files have been initialized

func LogAction

func LogAction(ctx infra.DnoteCtx, action Action) error

LogAction appends the action to the action log and updates the last_action timestamp

func LogActionAddBook

func LogActionAddBook(ctx infra.DnoteCtx, name string) error

func LogActionAddNote

func LogActionAddNote(ctx infra.DnoteCtx, noteUUID, bookName, content string, timestamp int64) error

func LogActionEditNote

func LogActionEditNote(ctx infra.DnoteCtx, noteUUID, bookName, content string, ts int64) error

func LogActionRemoveBook

func LogActionRemoveBook(ctx infra.DnoteCtx, name string) error

func LogActionRemoveNote

func LogActionRemoveNote(ctx infra.DnoteCtx, noteUUID, bookName string) error

func MigrateToDnoteDir

func MigrateToDnoteDir(ctx infra.DnoteCtx) error

MigrateToDnoteDir creates dnote directory if artifacts from the previous version of dnote are present, and moves the artifacts to the directory.

func NewBook

func NewBook(name string) infra.Book

NewBook returns a book

func NewNote

func NewNote(content string, ts int64) infra.Note

NewNote returns a note

func ReadActionLogContent

func ReadActionLogContent(ctx infra.DnoteCtx) ([]byte, error)

func ReadConfig

func ReadConfig(ctx infra.DnoteCtx) (infra.Config, error)

func ReadNoteContent

func ReadNoteContent(ctx infra.DnoteCtx) ([]byte, error)

ReadNoteContent reads the content of dnote

func ReadTimestamp

func ReadTimestamp(ctx infra.DnoteCtx) (infra.Timestamp, error)

ReadTimestamp gets the content of the timestamp file

func Reduce

func Reduce(ctx infra.DnoteCtx, action Action) error

Reduce transitions the local dnote state by consuming the action returned from the server

func ReduceAll

func ReduceAll(ctx infra.DnoteCtx, actions []Action) error

ReduceAll reduces all actions

func SanitizeContent

func SanitizeContent(s string) string

SanitizeContent sanitizes note content

func UpdateLastActionTimestamp

func UpdateLastActionTimestamp(ctx infra.DnoteCtx, val int64) error

func WriteActionLog

func WriteActionLog(ctx infra.DnoteCtx, actions []Action) error

func WriteConfig

func WriteConfig(ctx infra.DnoteCtx, config infra.Config) error

func WriteDnote

func WriteDnote(ctx infra.DnoteCtx, dnote infra.Dnote) error

WriteDnote persists the state of Dnote into the dnote file

func WriteTimestamp

func WriteTimestamp(ctx infra.DnoteCtx, timestamp infra.Timestamp) error

Types

type Action

type Action struct {
	ID        int             `json:"id"`
	Type      string          `json:"type"`
	Data      json.RawMessage `json:"data"`
	Timestamp int64           `json:"timestamp"`
}

func ReadActionLog

func ReadActionLog(ctx infra.DnoteCtx) ([]Action, error)

ReadActionLog returns the action log content

type AddBookData

type AddBookData struct {
	BookName string `json:"book_name"`
}

type AddNoteData

type AddNoteData struct {
	NoteUUID string `json:"note_uuid"`
	BookName string `json:"book_name"`
	Content  string `json:"content"`
}

type EditNoteData

type EditNoteData struct {
	NoteUUID string `json:"note_uuid"`
	BookName string `json:"book_name"`
	Content  string `json:"content"`
}

type RemoveBookData

type RemoveBookData struct {
	BookName string `json:"book_name"`
}

type RemoveNoteData

type RemoveNoteData struct {
	NoteUUID string `json:"note_uuid"`
	BookName string `json:"book_name"`
}

type RunEFunc

type RunEFunc func(*cobra.Command, []string) error

Jump to

Keyboard shortcuts

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