package histutil
import "src.elv.sh/pkg/cli/histutil"
Package histutil provides utilities for working with command history.
Index ¶
Package Files ¶
db.go db_store.go dedup_cursor.go doc.go hybrid_store.go mem_store.go store.go
Variables ¶
ErrEndOfHistory is returned by Cursor.Get if the cursor is currently over the edge.
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() (store.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) ([]store.Cmd, error) PrevCmd(upto int, prefix string) (store.Cmd, error) NextCmd(from int, prefix string) (store.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 store.Cmd) (int, error) // AllCmds returns all commands kept in the store. AllCmds() ([]store.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.
Package histutil imports 3 packages (graph) and is imported by 2 packages. Updated 2 weeks ago.
Tools for package owners.