Documentation
¶
Index ¶
- Constants
- Variables
- func BuildPreSelected(entries []Entry) map[string]bool
- func DefaultName(path string) string
- func ExpandEntries(entries []Entry) (paths map[string]bool, writable map[string]bool, err error)
- func HashEntry(name string) string
- func ReadFile(dir string, name string) (string, error)
- func ResolveHash(entries []Entry, prefix string) (string, error)
- func WriteFile(dir, name, content string) error
- type Entry
- type EntryType
- type HashTable
- type Reader
- type ResolvedFile
- type Vault
- func (v *Vault) AddDir(path, name string, recursive, writable bool) error
- func (v *Vault) AddFile(path, name string, writable bool) error
- func (v *Vault) Entries() []Entry
- func (v *Vault) Remove(name string) error
- func (v *Vault) RemoveByPath(path string) error
- func (v *Vault) ReplaceEntries(entries []Entry)
- func (v *Vault) ResolveIdentifier(id string) (string, error)
- func (v *Vault) Save() error
- func (v *Vault) SetWritable(name string, writable bool) error
Constants ¶
const ConfigFilename = ".pickaxe.json"
ConfigFilename is the name of the per-project config file.
Variables ¶
var ( ErrNotInitialized = errors.New("vault not initialized") ErrAlreadyExists = errors.New(".pickaxe.json already exists") ErrNameCollision = errors.New("name already in use") ErrNotFound = errors.New("no entry with that name") ErrAmbiguousHash = errors.New("ambiguous hash prefix") ErrReadOnly = errors.New("file is read-only") )
Functions ¶
func BuildPreSelected ¶
BuildPreSelected builds a set of already-registered paths for TUI pre-selection.
func DefaultName ¶
DefaultName derives the short name from a file or directory path.
func ExpandEntries ¶
ExpandEntries returns two maps: paths (all concrete .md file paths) and writable (paths whose parent entry has Writable=true). Unavailable files are skipped.
func ReadFile ¶
ReadFile opens the vault at dir and returns the content of the named file. Uses an O(1) map lookup after a single enumeration pass.
func ResolveHash ¶
ResolveHash finds the entry whose hash starts with prefix without building a full HashTable.
Types ¶
type Entry ¶
type Entry struct {
Type EntryType `json:"type"`
Path string `json:"path"`
Name string `json:"name"`
Recursive bool `json:"recursive,omitempty"`
Writable bool `json:"writable,omitempty"`
}
Entry represents one registered file or directory.
func Compact ¶
Compact takes a set of selected file paths and an optional writablePaths map, and returns the most compact []Entry representation. For each directory, if ALL .md files are selected, collapse to a dir entry. If all subdirs are also fully selected, upgrade to recursive. Mixed writability within a directory prevents dir collapse — individual file entries are emitted instead.
type HashTable ¶
type HashTable struct {
// contains filtered or unexported fields
}
HashTable maps entry names to their hashes and shortest unique prefix lengths.
func NewHashTable ¶
NewHashTable builds a HashTable from a slice of entries.
func (*HashTable) ResolvePrefix ¶
ResolvePrefix finds the entry name whose hash starts with prefix. Returns ErrAmbiguousHash if multiple entries match, ErrNotFound if none.
func (*HashTable) ShortPrefixLen ¶
ShortPrefixLen returns the length of the shortest unique prefix for the named entry, capped at 8 (the display hash length).
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader is a thin VaultReader implementation that delegates to the package-level ListFiles, ReadFile, and WriteFile functions, re-reading from disk each call.
func (*Reader) ListFiles ¶
func (r *Reader) ListFiles() ([]ResolvedFile, error)
type ResolvedFile ¶
ResolvedFile is a concrete file path with its display name and availability info.
func ListFiles ¶
func ListFiles(dir string) ([]ResolvedFile, error)
ListFiles opens the vault at dir and returns all resolved files. Re-reads from disk every call.
type Vault ¶
type Vault struct {
// contains filtered or unexported fields
}
Vault owns a single .pickaxe.json and its mutations.
func (*Vault) AddFile ¶
AddFile registers a single file. name may be empty (defaults to filename sans ext).
func (*Vault) RemoveByPath ¶
RemoveByPath removes the entry with the given path. Returns ErrNotFound if absent.
func (*Vault) ReplaceEntries ¶
ReplaceEntries replaces all entries with the given slice.
func (*Vault) ResolveIdentifier ¶
ResolveIdentifier returns the entry name matching id by exact name first, then by hash prefix. Returns ErrAmbiguousHash or ErrNotFound on failure.