Documentation
¶
Overview ¶
Package histutil provides utilities for working with command history.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrEndOfHistory = errors.New("end of history")
ErrEndOfHistory is returned by Cursor.Get if the cursor is currently over the edge.
Functions ¶
This section is empty.
Types ¶
type Cursor ¶
type Cursor interface {
// Prev moves the cursor to the previous command.
Prev()
// Next moves the cursor to the next command.
Next()
// Get returns the command the cursor is currently at, or any error if the
// cursor is in an invalid state. If the cursor is "over the edge", the
// error is ErrEndOfHistory.
Get() (storedefs.Cmd, error)
}
Cursor is used to navigate a Store.
func NewDedupCursor ¶
NewDedupCursor returns a cursor that skips over all duplicate entries.
type DB ¶
type DB interface {
NextCmdSeq() (int, error)
AddCmd(cmd string) (int, error)
CmdsWithSeq(from, upto int) ([]storedefs.Cmd, error)
PrevCmd(upto int, prefix string) (storedefs.Cmd, error)
NextCmd(from int, prefix string) (storedefs.Cmd, error)
}
DB is the interface of the storage database.
type FaultyInMemoryDB ¶
type FaultyInMemoryDB interface {
DB
// SetOneOffError causes the next operation on the database to return the
// given error.
SetOneOffError(err error)
}
FaultyInMemoryDB is an in-memory DB implementation that can be injected one-off errors. It is useful in tests.
func NewFaultyInMemoryDB ¶
func NewFaultyInMemoryDB(cmds ...string) FaultyInMemoryDB
NewFaultyInMemoryDB creates a new FaultyInMemoryDB with the given commands.
type Store ¶
type Store interface {
// AddCmd adds a new command history entry and returns its sequence number.
// Depending on the implementation, the Store might respect cmd.Seq and
// return it as is, or allocate another sequence number.
AddCmd(cmd storedefs.Cmd) (int, error)
// AllCmds returns all commands kept in the store.
AllCmds() ([]storedefs.Cmd, error)
// Cursor returns a cursor that iterating through commands with the given
// prefix. The cursor is initially placed just after the last command in the
// store.
Cursor(prefix string) Cursor
}
Store is an abstract interface for history store.
func NewDBStore ¶
NewDBStore returns a Store backed by a database with the view of all commands frozen at creation.
func NewHybridStore ¶
NewHybridStore returns a store that provides a view of all the commands that exists in the database, plus a in-memory session history.
func NewMemStore ¶
NewMemStore returns a Store that stores command history in memory.