mirror of
https://github.com/cheat/cheat.git
synced 2026-03-07 11:13:33 +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 sheet provides functionality for parsing and managing individual cheat sheets.
|
|
//
|
|
// A sheet represents a single cheatsheet file containing helpful commands, notes,
|
|
// or documentation. Sheets can include optional YAML frontmatter for metadata
|
|
// such as tags and syntax highlighting preferences.
|
|
//
|
|
// # Sheet Format
|
|
//
|
|
// Sheets are plain text files that may begin with YAML frontmatter:
|
|
//
|
|
// ---
|
|
// syntax: bash
|
|
// tags: [networking, linux, ssh]
|
|
// ---
|
|
// # Connect to remote server
|
|
// ssh user@hostname
|
|
//
|
|
// # Copy files over SSH
|
|
// scp local_file user@hostname:/remote/path
|
|
//
|
|
// The frontmatter is optional. If omitted, the sheet will use default values.
|
|
//
|
|
// # Core Types
|
|
//
|
|
// The Sheet type contains:
|
|
// - Title: The sheet's name (derived from filename)
|
|
// - Path: Full filesystem path to the sheet
|
|
// - Text: The content of the sheet (without frontmatter)
|
|
// - Tags: Categories assigned to the sheet
|
|
// - Syntax: Language hint for syntax highlighting
|
|
// - ReadOnly: Whether the sheet can be modified
|
|
//
|
|
// Key Functions
|
|
//
|
|
// - New: Creates a new Sheet from a file path
|
|
// - Parse: Extracts frontmatter and content from sheet text
|
|
// - Search: Searches sheet content using regular expressions
|
|
// - Colorize: Applies syntax highlighting to sheet content
|
|
//
|
|
// # Syntax Highlighting
|
|
//
|
|
// The package integrates with the Chroma library to provide syntax highlighting.
|
|
// Supported languages include bash, python, go, javascript, and many others.
|
|
// The syntax can be specified in the frontmatter or auto-detected.
|
|
//
|
|
// Example Usage
|
|
//
|
|
// // Load a sheet from disk
|
|
// s, err := sheet.New("/path/to/sheet", []string{"personal"}, false)
|
|
// if err != nil {
|
|
// log.Fatal(err)
|
|
// }
|
|
//
|
|
// // Search for content
|
|
// matches, err := s.Search("ssh", false)
|
|
// if err != nil {
|
|
// log.Fatal(err)
|
|
// }
|
|
//
|
|
// // Apply syntax highlighting
|
|
// colorized, err := s.Colorize(config)
|
|
// if err != nil {
|
|
// log.Fatal(err)
|
|
// }
|
|
package sheet
|