mirror of
https://github.com/cheat/cheat.git
synced 2026-03-07 03:03:32 +01:00
Bug fixes: - Fix inverted pager detection logic (returned error instead of path) - Fix repo.Clone ignoring destination directory parameter - Fix sheet loading using append on pre-sized slices - Clean up partial files on copy failure - Trim whitespace from editor config Security: - Add path traversal protection for cheatsheet names Performance: - Move regex compilation outside search loop - Replace string concatenation with strings.Join in search Build: - Remove go:generate; embed config and usage as string literals - Parallelize release builds - Add fuzz testing infrastructure Testing: - Improve test coverage from 38.9% to 50.2% - Add fuzz tests for search, filter, tags, and validation Documentation: - Fix inaccurate code examples in HACKING.md - Add missing --conf and --all options to man page - Add ADRs for path traversal, env parsing, and search parallelization - Update CONTRIBUTING.md to reflect project policy Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
66 lines
1.9 KiB
Go
66 lines
1.9 KiB
Go
// Package sheets manages collections of cheat sheets across multiple cheatpaths.
|
|
//
|
|
// The sheets package provides functionality to:
|
|
// - Load sheets from multiple cheatpaths
|
|
// - Consolidate duplicate sheets (with precedence rules)
|
|
// - Filter sheets by tags
|
|
// - Sort sheets alphabetically
|
|
// - Extract unique tags across all sheets
|
|
//
|
|
// # Loading Sheets
|
|
//
|
|
// Sheets are loaded recursively from cheatpath directories, excluding:
|
|
// - Hidden files (starting with .)
|
|
// - Files in .git directories
|
|
// - Files with extensions (sheets have no extension)
|
|
//
|
|
// # Consolidation
|
|
//
|
|
// When multiple cheatpaths contain sheets with the same name, consolidation
|
|
// rules apply based on the order of cheatpaths. Sheets from earlier paths
|
|
// override those from later paths, allowing personal sheets to override
|
|
// community sheets.
|
|
//
|
|
// Example:
|
|
//
|
|
// cheatpaths:
|
|
// 1. personal: ~/cheat
|
|
// 2. community: ~/cheat/community
|
|
//
|
|
// If both contain "git", the version from "personal" is used.
|
|
//
|
|
// # Filtering
|
|
//
|
|
// Sheets can be filtered by:
|
|
// - Tags: Include only sheets with specific tags
|
|
// - Cheatpath: Include only sheets from specific paths
|
|
//
|
|
// Key Functions
|
|
//
|
|
// - Load: Loads all sheets from the given cheatpaths
|
|
// - Filter: Filters sheets by tag
|
|
// - Consolidate: Merges sheets from multiple paths with precedence
|
|
// - Sort: Sorts sheets alphabetically by title
|
|
// - Tags: Extracts all unique tags from sheets
|
|
//
|
|
// Example Usage
|
|
//
|
|
// // Load sheets from all cheatpaths
|
|
// allSheets, err := sheets.Load(cheatpaths)
|
|
// if err != nil {
|
|
// log.Fatal(err)
|
|
// }
|
|
//
|
|
// // Consolidate to handle duplicates
|
|
// consolidated := sheets.Consolidate(allSheets)
|
|
//
|
|
// // Filter by tag
|
|
// filtered := sheets.Filter(consolidated, "networking")
|
|
//
|
|
// // Sort alphabetically
|
|
// sheets.Sort(filtered)
|
|
//
|
|
// // Get all unique tags
|
|
// tags := sheets.Tags(consolidated)
|
|
package sheets
|