This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
make build # Build executables to ./dist folder (uses GoReleaser)
make test # Run all tests
make coverage # Run tests with coverage report (add html=true for browser view)
make generate # Regenerate OpenHue API client from OpenAPI spec
make tidy # Clean go.mod dependencies
make clean # Remove dist folder and coverage filesTo run a single test:
go test ./cmd/setup -run TestDiscoverThis is a Cobra-based CLI for controlling Philips Hue smart lighting. It uses the openhue-go library for API communication.
- Entry point:
main.go→cmd/root.go(Execute function) - Command groups: Two groups defined -
hue(light control) andconfig(setup commands) - Context pattern:
openhue.Contextholds shared state (IOStreams, BuildInfo, Home, Config) passed to all commands
openhue/- Core domain: Config management, Context, HomeModel (hierarchical data model)cmd/- Cobra commands organized by action (get/,set/,setup/,version/)util/- Helpers for output formatting, color conversion, logging
The HomeModel in openhue/home_model.go creates a hierarchical view of Hue resources:
HomeModel→Room[]→Device[]→Light- Each resource embeds a
Resourcestruct with Id, Name, Type, Parent pointer - Resources wrap raw HueData from the API and add convenience methods
- Search functions (
SearchLights,SearchRooms,SearchScenes) accept name OR id for flexibility
Commands in the hue group trigger LoadHomeIfNeeded in PersistentPreRun, which loads the full HomeModel from the bridge. Config commands skip this overhead.
Config stored in ~/.openhue/config.yaml (or $XDG_CONFIG_HOME/openhue/). Contains bridge IP and application key. Commands listed in CommandsWithNoConfig can run without setup.
- Use
openhue.NewTestContext(home)to create test contexts with mock HomeModel - Test files use
openhue/test/assertfor custom assertions - Tests use
stretchr/testifyfor standard assertions