This is the official Home Assistant CLI tool written in Go, providing command-line interface to interact with the Home Assistant Supervisor. The CLI enables users to manage apps, control the core system, handle audio/network settings, manage backups, and perform various system operations.
The CLI is communicating with the Supervisor using the Supervisor's HTTP REST API.
main.go- Entry point of the applicationcmd/- Contains all CLI command implementations using Cobra frameworkclient/- HTTP client functionality for API communicationspinner/- Progress spinner implementation- Root files - Configuration and documentation
- Language: Go (use modern syntax)
- CLI Framework: Cobra (github.com/spf13/cobra)
- HTTP Client: Resty (github.com/go-resty/resty/v2)
- Configuration: Viper (github.com/spf13/viper)
- Logging: Go stdlib log/slog
The CLI provides the following main command categories:
apps- Install, update, remove and configure Home Assistant appsaudio- Audio plug-in managementauthentication- Authentication for Home Assistant userscli- CLI plug-in managementcore- Home Assistant Core controldns- DNS plug-in managementdocker- Docker related configurationhardware- System hardware informationhost- Host OS controlinfo- General Home Assistant informationmulticast- Multicast plug-in configurationnetwork- Network configuration and managementobserver- Observer plug-in managementos- Home Assistant OS specific operationsresolution- Resolution center for issues and solutionsbackups- Backup creation, restoration, and managementsupervisor- Supervisor monitoring and control
- API Endpoint: Configurable via
SUPERVISOR_ENDPOINTenvironment variable - Authentication: Uses API tokens via
SUPERVISOR_API_TOKENenvironment variable - Config File: Optional config file support (default:
$HOME/.homeassistant.yaml)
- Build:
CGO_ENABLED=0 go build -ldflags="-s -w" -o "ha" - Test:
go test ./... - Format:
gofmt -s
- Command files follow naming pattern:
<component>_<action>.go - Each command typically has its own file in the
cmd/directory - Helper functions are in
client/helper.go - Main client logic is in
client/client.go
- Uses Cobra for command structure and flag parsing
- Resty for HTTP API calls to Home Assistant Supervisor
- Viper for configuration management
- Go stdlib log/slog for structured logging
- Custom spinner implementation for progress indication
- Unit tests available in
client/helper_test.go - Test command:
go test ./...
- Create feature branch
- Commit changes
- Rebase against master
- Run tests with
go test ./... - Format code with
gofmt -s - Create Pull Request
This CLI is designed to work with Home Assistant Supervisor API and is commonly used in Home Assistant Operating System environments, SSH apps, and development setups.