Documentation
¶
Overview ¶
Package store handles snippet persistence as a single JSON file.
The on-disk format is documented in docs/format.md. Keep that doc and this package in sync — external compatibility lives there.
Index ¶
- Constants
- Variables
- func DefaultPath() (string, error)
- func Save(path string, f *File) error
- type File
- func (f *File) Add(s Snippet) error
- func (f *File) Delete(key string) error
- func (f *File) Get(key string) (*Snippet, error)
- func (f *File) Has(key string) bool
- func (f *File) Search(query string) []Snippet
- func (f *File) SortedKeys() []string
- func (f *File) Touch(key string, at time.Time) error
- func (f *File) Update(oldKey string, newSnippet Snippet) error
- type Snippet
Constants ¶
const FormatVersion = 1
Variables ¶
var ( ErrNotFound = errors.New("snippet not found") ErrExists = errors.New("snippet already exists") ErrEmptyKey = errors.New("key must not be empty") )
Common errors.
Functions ¶
func DefaultPath ¶
DefaultPath returns the default snippet file location.
PE_DIR overrides everything. Otherwise falls back to ~/.pe/pe.json (per the project spec). XDG paths are intentionally NOT consulted — keeping a single, stable, easy-to-remember location is a feature.
Types ¶
type File ¶
File is the root JSON document on disk.
func (*File) Add ¶
Add inserts a new snippet. Returns ErrExists if the key is taken. CreatedAt / UpdatedAt are stamped if zero.
func (*File) Search ¶
Search returns all snippets whose key, description, value, or tags contain the query (case-insensitive). Results are sorted by key.
func (*File) SortedKeys ¶
SortedKeys returns all keys in sorted order.
type Snippet ¶
type Snippet struct {
Key string `json:"key"`
Value string `json:"value"`
Description string `json:"description,omitempty"`
Tags []string `json:"tags,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
LastUsedAt *time.Time `json:"lastUsedAt,omitempty"`
UseCount int `json:"useCount"`
}
Snippet is a single registered phrase / command / prompt fragment.