Skip to content

Latest commit

 

History

History
44 lines (29 loc) · 1.79 KB

File metadata and controls

44 lines (29 loc) · 1.79 KB

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Overview

gdgh is a zero-dependency Go CLI tool that converts git diffs into styled HTML pages. It supports line-by-line and side-by-side views with light/dark color schemes.

Commands

# Build
go build -o gdgh ./cmd

# Run directly
go run ./cmd [flags]

# Run tests
go test ./...

# Run a single package's tests
go test ./internal/diff/
go test ./internal/html/

# Example usage
go run ./cmd -- HEAD~1                         # diff last commit, open in browser
go run ./cmd -s side -o stdout -- HEAD~1       # side-by-side to stdout
go run ./cmd -i file testdata/sample.diff      # from file
cat testdata/sample.diff | go run ./cmd -i stdin -s side

Architecture

The pipeline is: parse → render → output.

  • cmd/main.go — CLI entry point. Handles flags, reads diff input (from git diff, a file, or stdin), invokes the parser and renderer, then writes output (browser preview, stdout, or file).
  • internal/diff/parser.go — Parses unified diff text into DiffResult (containing []FileDiff, each with []Hunk, each with []Line). Handles both git diff format and plain unified diffs.
  • internal/html/renderer.go — Takes a *diff.DiffResult and Options, returns a complete self-contained HTML string. CSS is inlined via getCSS(). Supports two render paths: renderFileLineByLine and renderFileSideBySide (which calls buildSidePairs to align removed/added lines).

There are no external dependencies — the module only uses the Go standard library.

Test Data

testdata/ contains a sample diff (sample.diff) and reference HTML outputs (output-line.html, output-side.html, output-side-dark.html) useful for verifying renderer output visually.