How alecthomas/kong works
Kong is a Go library for turning a Go struct and its tags into a command-line interface. The main workflow starts when an application supplies its CLI structure and arguments: Kong builds a command model, scans and parses input into a Context, maps values, validates them, and makes the selected command available to run. Separate capabilities include generated contextual help, custom decoders, configuration and external defaults, hooks, dynamic commands, and dependency injection. The graph follows README-documented behavior and sampled files; unsampled implementation details are not asserted.
Main entry points: context.go Parse context · options.go Configuration options · kong.go Kong API · build.go Model builder
Components 15
CLI Definition
- Model builder
build.go - Tag metadata
tag.go
Parse And Execute
- Kong API
kong.go - Argument scanner
scanner.go - Parse context
context.go - Value decoders
mapper.go - Command callbacks
callbacks.go
Customization
- Configuration options
options.go - Default resolvers
resolver.go - Lifecycle hooks
hooks.go - Variable interpolation
interpolate.go
Help And Errors
- Contextual help
help.go - Parse errors
error.go
Other components
- Application developer
- CLI user
Connections 17
- Application developer → Kong API: defines CLI
README.md - CLI user → Kong API: supplies arguments
README.md - Kong API → Model builder: builds model
README.md - Model builder → Tag metadata: reads tags
- Kong API → Parse context: parses input
README.md - Parse context → Argument scanner: scans arguments
context.go - Parse context → Value decoders: decodes values
- Parse context → Default resolvers: resolves defaults
README.md - Parse context → Contextual help: prints help
README.md - Parse context → Parse errors: reports errors
- Parse context → Command callbacks: runs command
README.md - Application developer → Configuration options: configures behavior
README.md - Configuration options → Default resolvers: loads configuration
options.go - Configuration options → Value decoders: registers decoders
options.go - Configuration options → Lifecycle hooks: registers hooks
options.go - Configuration options → Variable interpolation: configures variables
- Contextual help → Variable interpolation: interpolates text
README.md