mirror of
https://github.com/cheat/cheat.git
synced 2026-03-07 11:13:33 +01:00
Previously cheat only checked the current working directory for a .cheat subdirectory. Now it walks upward through ancestor directories, stopping at the first .cheat directory found. This mirrors how git discovers .git directories, so users can place .cheat at their project root and have it work from any subdirectory. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
65 lines
2.0 KiB
Go
65 lines
2.0 KiB
Go
// Package cheatpath manages collections of cheat sheets organized in filesystem directories.
|
|
//
|
|
// A Cheatpath represents a directory containing cheat sheets, with associated
|
|
// metadata such as tags and read-only status. Multiple cheatpaths can be
|
|
// configured to organize sheets from different sources (personal, community, work, etc.).
|
|
//
|
|
// # Cheatpath Structure
|
|
//
|
|
// Each cheatpath has:
|
|
// - Name: A friendly identifier (e.g., "personal", "community")
|
|
// - Path: The filesystem path to the directory
|
|
// - Tags: Tags automatically applied to all sheets in this path
|
|
// - ReadOnly: Whether sheets in this path can be modified
|
|
//
|
|
// Example configuration:
|
|
//
|
|
// cheatpaths:
|
|
// - name: personal
|
|
// path: ~/cheat
|
|
// tags: []
|
|
// readonly: false
|
|
// - name: community
|
|
// path: ~/cheat/community
|
|
// tags: [community]
|
|
// readonly: true
|
|
//
|
|
// # Directory-Scoped Cheatpaths
|
|
//
|
|
// The package supports directory-scoped cheatpaths via `.cheat` directories.
|
|
// When running cheat, the tool walks upward from the current working directory
|
|
// to the filesystem root, stopping at the first `.cheat` directory found. That
|
|
// directory is temporarily added to the available cheatpaths.
|
|
//
|
|
// # Precedence and Overrides
|
|
//
|
|
// When multiple cheatpaths contain a sheet with the same name, the sheet
|
|
// from the most "local" cheatpath takes precedence. This allows users to
|
|
// override community sheets with personal versions.
|
|
//
|
|
// Key Functions
|
|
//
|
|
// - Filter: Filters cheatpaths by name
|
|
// - Validate: Ensures cheatpath configuration is valid
|
|
// - Writeable: Returns the first writeable cheatpath
|
|
//
|
|
// Example Usage
|
|
//
|
|
// // Filter cheatpaths to only "personal"
|
|
// filtered, err := cheatpath.Filter(paths, "personal")
|
|
// if err != nil {
|
|
// log.Fatal(err)
|
|
// }
|
|
//
|
|
// // Find a writeable cheatpath
|
|
// writeable, err := cheatpath.Writeable(paths)
|
|
// if err != nil {
|
|
// log.Fatal(err)
|
|
// }
|
|
//
|
|
// // Validate cheatpath configuration
|
|
// if err := cheatpath.Validate(paths); err != nil {
|
|
// log.Fatal(err)
|
|
// }
|
|
package cheatpath
|