snip

command module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 5, 2026 License: MIT Imports: 1 Imported by: 0

README ยถ

๐Ÿ“ฆ SNIP - Code Snippet Manager

A beautiful terminal-based code snippet manager built with Go and Bubble Tea

Go Version License Release Test Coverage Go Report Card

โœจ Features

  • ๐ŸŽจ Beautiful TUI - Interactive terminal interface with tabbed navigation
  • ๐Ÿ“ Category Management - Organize snippets into logical categories
  • ๐Ÿท๏ธ Tag System - Multi-tag support for flexible organization
  • ๐Ÿ” Full-Text Search - Quickly find snippets by title, description, or code
  • โŒจ๏ธ Syntax Highlighting - Code editor with line numbers
  • ๐Ÿš€ Dual Interface - Use interactive TUI or traditional CLI commands

๐Ÿ“ธ Screenshots

Interactive TUI Mode
  โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎโ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎโ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎโ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
  โ”‚       โŒจ Home       โ”‚โ”‚     Categories     โ”‚โ”‚        Tags        โ”‚โ”‚      Snippets      โ”‚
  โ”‚                    โ””โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
  โ”‚                                                                                      โ”‚
  โ”‚    โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ                                                                          โ”‚
  โ”‚  โ–ˆโ–ˆ        โ–ˆโ–ˆ                                                                        โ”‚
  โ”‚  โ–ˆโ–ˆ  โ–ˆโ–ˆ  โ–ˆโ–ˆ  โ–ˆโ–ˆ                                                                      โ”‚
  โ”‚  โ–ˆโ–ˆ  โ–ˆโ–ˆ  โ–ˆโ–ˆ  โ–ˆโ–ˆ                                                                      โ”‚
  โ”‚  โ–ˆโ–ˆ          โ–ˆโ–ˆ                                                                      โ”‚
  โ”‚  โ–ˆโ–ˆ  โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ โ–ˆโ–ˆ                                                                     โ”‚
  โ”‚  โ–ˆโ–ˆโ–ˆโ–ˆ      โ–ˆโ–ˆโ–ˆโ–ˆ                                                                      โ”‚
  โ”‚                                                                                      โ”‚
  โ”‚  SNIP - Code Snippet Manager                                                         โ”‚
  โ”‚                                                                                      โ”‚
  โ”‚  Welcome! Use the tabs above to navigate:                                            โ”‚
  โ”‚  - Home - You are here                                                               โ”‚
  โ”‚  - Categories - Manage snippet categories                                            โ”‚
  โ”‚  - Tags - Manage snippet tags                                                        โ”‚
  โ”‚  - Snippets - Manage code snippets                                                   โ”‚
  โ”‚                                                                                      โ”‚
  โ”‚  Navigation:                                                                         โ”‚
  โ”‚    Ctrl+F      - Toggle between Interactive and Navigation mode                      โ”‚
  โ”‚    Tab         - Next tab (in Navigation mode)                                       โ”‚
  โ”‚    Shift+Tab   - Previous tab (in Navigation mode)                                   โ”‚
  โ”‚    โ†/โ†’         - Switch tabs (in Navigation mode)                                    โ”‚
  โ”‚    PgUp/PgDn   - Scroll content (in Interactive mode)                                โ”‚
  โ”‚    Ctrl+โ†/โ†’    - Scroll horizontally                                                 โ”‚
  โ”‚    Ctrl+C      - Quit                                                                โ”‚
  โ”‚                                                                                      โ”‚
  โ”‚  Mode Indicators:                                                                    โ”‚
  โ”‚    โŒจ (green)   - Interactive mode: Components receive keyboard input                 โ”‚
  โ”‚    โ‡„ (blue)    - Navigation mode: Tab switching and scrolling enabled                โ”‚
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

  Ctrl+F: toggle mode | Ctrl+C: quit

๐Ÿš€ Quick Start

Installation
Download Pre-built Binary

Download the latest release for your platform from the releases page.

Linux/macOS:

# Download and install (replace VERSION with actual version)
curl -L https://github.com/7-Dany/snip/releases/download/vVERSION/snip-linux-amd64 -o snip
chmod +x snip
sudo mv snip /usr/local/bin/

Windows (PowerShell):

# Download from releases page and add to PATH
Build from Source
# Clone the repository
git clone https://github.com/7-Dany/snip.git
cd snip

# Build and install
make build
sudo make install

# Or use go install
go install
First Run
# Launch interactive TUI
snip

# Or use CLI commands, note: to work with commands snip must be followed with arguments.
snip snippet create
snip snippet list
snip help

๐Ÿ“– Usage

Interactive TUI Mode

The recommended way to use SNIP is through the interactive TUI:

snip

Keyboard Shortcuts:

Key Action
Ctrl+F Toggle between Interactive and Navigation mode
Tab / Shift+Tab Navigate between tabs (Navigation mode)
โ† / โ†’ Switch tabs (Navigation mode)
โ†‘ / โ†“ Navigate lists/menus
Enter Select item / Confirm action
/ Start search/filter
a Add new item
r Refresh list
? Show help
Esc Cancel / Go back
Ctrl+C Quit application

In Code Editor:

Key Action
Tab / Shift+Tab Navigate between fields
Alt+C Select category
Alt+T Manage tags
Ctrl+S Save snippet
Esc Cancel editing
CLI Commands
Snippet Management
# Create a new snippet interactively
snip snippet create

# List all snippets
snip snippet list

# List snippets with filters
snip snippet list --language go
snip snippet list --category 1
snip snippet list --tag 2

# Show a specific snippet
snip snippet show 5

# Update a snippet
snip snippet update 5

# Delete a snippet
snip snippet delete 5

# Search snippets
snip snippet search "binary tree"
Category Management
# Create a category
snip category create algorithms
snip category create  # Interactive mode

# List all categories
snip category list

# Delete a category
snip category delete 3
Tag Management
# Create a tag
snip tag create performance
snip tag create  # Interactive mode

# List all tags
snip tag list

# Delete a tag
snip tag delete 7
Help
# General help
snip help

# Topic-specific help
snip help snippet
snip help category
snip help tag

๐Ÿ—๏ธ Architecture

snip/
โ”œโ”€โ”€ cmd/                   # Application entry points
โ”‚   โ””โ”€โ”€ main.go            # Main CLI application
โ”œโ”€โ”€ internal/
โ”‚   โ”œโ”€โ”€ cli/               # CLI layer
โ”‚   โ”‚   โ”œโ”€โ”€ commands/      # CLI command handlers
โ”‚   โ”‚   โ”œโ”€โ”€ components/    # Reusable Bubble Tea UI components
โ”‚   โ”‚   โ””โ”€โ”€ tui/           # Terminal UI implementation
โ”‚   โ”œโ”€โ”€ domain/            # Business logic and entities
โ”‚   โ””โ”€โ”€ storage/           # Data persistence layer
โ””โ”€โ”€ main.go
Key Components
  • Domain Layer: Pure business logic (snippets, categories, tags)
  • Storage Layer: JSON-based repositories with transaction support
  • CLI Commands: Traditional command-line interface
  • TUI: Interactive terminal interface using Bubble Tea
  • Components: Reusable UI widgets (tables, editors, menus, dialogs)

๐Ÿงช Testing

Test Coverage

SNIP maintains comprehensive test coverage across its core components:

Component Coverage Notes
Domain Layer ~100.0% Business logic fully tested
Storage Layer ~99.5% Repository operations and transactions
CLI Commands ~85% Command handlers and validation
Overall ~85% Excluding interactive TUI components
# Run all tests
make test

# Run tests with coverage report
go test ./... -cover

# Generate detailed coverage report
go test ./... -coverprofile=coverage.out
go tool cover -html=coverage.out
Testing Approach
โœ… What We Test
  • Business Logic: All domain entities, validation rules, and state management
  • Data Persistence: Repository CRUD operations, queries, and transactions
  • CLI Commands: Command parsing, argument validation, and error handling
  • Error Paths: Database errors, invalid input, and edge cases
โš ๏ธ What We Don't Test (And Why)

Interactive TUI Components are intentionally excluded from automated testing for the following reasons:

  1. Framework Limitations: Bubble Tea's event-driven architecture and terminal rendering make unit testing impractical without extensive mocking
  2. Testing Complexity: UI interactions involve complex state machines, terminal dimensions, and timing-dependent updates that are difficult to reproduce in tests
  3. Visual Nature: TUI correctness is inherently visual - automated tests can't validate layout, colors, or user experience
  4. Rapid UI Changes: UI/UX iterations are frequent and would require constant test maintenance
  5. Manual QA is More Effective: Interactive components are better validated through:
    • Manual testing during development
    • Smoke tests before releases
    • User feedback and bug reports

User Input Prompts (like delete confirmations) are also not fully tested because:

  • They rely on fmt.Scanln() which reads from stdin
  • Mocking stdin in Go tests is complex and fragile
  • These are simple UI flows with minimal business logic
  • Refactoring for testability would add unnecessary complexity
๐ŸŽฏ Testing Strategy

Our testing strategy focuses on:

  • High-value tests: Core business logic and data integrity
  • Fast feedback: Unit tests run in milliseconds
  • Maintainability: Tests are simple and don't require complex mocks
  • Confidence: Critical paths have multiple test scenarios

The combination of automated tests for logic layers and manual testing for UI provides the best balance of confidence and development velocity.

Running Tests
# Run all tests
go test ./...

# Run tests with verbose output
go test -v ./...

# Run tests for specific package
go test ./internal/domain/...
go test ./internal/storage/...
go test ./internal/cli/commands/...

# Run tests with race detection
go test -race ./...

# Generate coverage report
go test -coverprofile=coverage.out ./...
go tool cover -func=coverage.out

# View coverage in browser
go tool cover -html=coverage.out
Test Organization
internal/
โ”œโ”€โ”€ domain/
โ”‚   โ”œโ”€โ”€ snippet_test.go      # Domain entity tests
โ”‚   โ”œโ”€โ”€ category_test.go
โ”‚   โ””โ”€โ”€ tag_test.go
โ”œโ”€โ”€ storage/
โ”‚   โ”œโ”€โ”€ snippet_repo_test.go # Repository tests
โ”‚   โ”œโ”€โ”€ category_repo_test.go
โ”‚   โ””โ”€โ”€ tag_repo_test.go
โ””โ”€โ”€ cli/
    โ””โ”€โ”€ commands/
        โ”œโ”€โ”€ snippet_test.go   # CLI command tests
        โ”œโ”€โ”€ category_test.go
        โ””โ”€โ”€ tag_test.go

๐Ÿ› ๏ธ Development

Prerequisites
  • Go 1.25 or higher
Building
# Build for current platform
make build

# Build for all platforms
make build-all

# Run tests
make test

# Clean build artifacts
make clean
Development Workflow
  1. Make your changes
  2. Run tests: make test
  3. Check coverage: go test -cover ./...
  4. Test manually with: go run main.go
  5. Build: make build

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Contribution Guidelines
  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Write tests for new functionality (where applicable)
  4. Ensure all tests pass (go test ./...)
  5. Commit your changes (git commit -m 'Add some amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request
What to Test
  • โœ… Do add tests for: Domain logic, repository operations, CLI command handlers
  • โš ๏ธ Optional for: TUI components (manual testing is acceptable)
  • โœ… Always test: Error handling and edge cases

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Built with Bubble Tea - amazing TUI framework
  • Uses Lipgloss for styling
  • Inspired by the need for a simple, elegant snippet manager

๐Ÿ“ฌ Contact


โญ If you find this project useful, please consider giving it a star!

Documentation ยถ

The Go Gopher

There is no documentation for this package.

Directories ยถ

Path Synopsis
internal
cli/commands
Package commands provides the CLI command handlers for SNIP.
Package commands provides the CLI command handlers for SNIP.
cli/config
Package config handles application configuration management.
Package config handles application configuration management.
domain
Package domain contains the core business entities and logic for the snippet manager.
Package domain contains the core business entities and logic for the snippet manager.
storage
Package storage provides JSON file-based persistence for SNIP entities.
Package storage provides JSON file-based persistence for SNIP entities.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL