kingpin

A fluent, type-safe command-line flag and argument parser for Go, with nested subcommands and rich usage help.

Library
Go
vv2.4.0
3,568 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
64 /100 Good
Development Activity 56
Maintenance 28
Community 72
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
65 /100 Good
Architecture 78
Code Quality 72
Innovation 55
Learning Curve 55

Kingpin is a fluent-style, type-safe command-line parser for Go that lets developers define flags, positional arguments, and arbitrarily nested subcommands through a chainable API. It automatically generates detailed, contextual usage help whenever —help appears anywhere on the command line, and supports POSIX-style short-flag combining, environment-variable fallbacks, default values, and reading arguments from files via @<file> expansion.

The library is commonly used to build both small single-command CLIs and large multi-command tools with git-style subcommands, similar in spirit to Cobra or Clap in other ecosystems. Kingpin v2 is now in contributions-only maintenance mode — the original author has moved on to a lighter alternative (Kong) — but the library remains stable, widely depended upon, and functionally complete for existing use cases.

What You Get

  • Fluent flag/argument/command builder API with type-safe value parsing (Bool, Int, Duration, IP, ExistingFile, byte sizes, and more)
  • Automatic, template-customizable usage help, long help, and man page generation
  • Nested subcommands with per-command flags, positional arguments, and Action() callbacks
  • Shell completion script generation for bash, zsh, and fish, plus dynamic completion support
  • Support for reading arguments from files via @<file> expansion

Common Use Cases

  • Building git-style CLIs with multiple subcommands and shared global flags
  • Generating consistent —help and —help-man output across a large command surface
  • Parsing typed flags and arguments (durations, IPs, byte sizes) without manual conversion code
  • Adding shell autocompletion to an existing Go CLI tool

Under The Hood

Architecture Kingpin structures parsing around composable clause types — an Application (app.go) embeds a cmdMixin that owns a flagGroup, argGroup, and cmdGroup (model.go), while FlagClause, ArgClause, and CmdClause builders feed a tokenizing Parser (parser.go) that walks a linear Token stream (TokenShort/TokenLong/TokenArg) into a ParseContext capturing the SelectedCommand plus fully resolved values before dispatching registered Action() callbacks. This is a layered, single-responsibility flow — tokenize, resolve clauses, populate context, invoke actions — with a clean split between definition-time builder methods and parse-time state, though the coupling between Application and the internal flag/arg/cmd groups means adding a genuinely new clause kind would touch app.go, model.go, and parser.go together.

Tech Stack Kingpin is a dependency-light, pure Go library (go.mod targets an old, broadly compatible Go version) whose only non-test runtime dependencies are a byte-size parser and a human-friendly duration parser, with an additional indirect YAML dependency; tests rely on a well-known assertion library. Value parsing for its many built-in flag/argument types is code-generated via a small generator command driven by a template and a JSON type manifest, and CI runs through GitHub Actions using a pinned, vendored toolchain rather than relying on the runner’s default Go install.

Code Quality The library ships a broad set of test files covering the application, command, flag, parser, usage-rendering, and value-parsing surfaces, written against a standard assertion-style testing library rather than raw manual checks. Error handling is explicit and typed — each value’s Set method returns a wrapped parsing error instead of panicking — though a few internal invariants intentionally panic as “should never happen” guards. Naming follows conventional Go idiom throughout, and formatting/vetting are enforced implicitly via the pinned CI toolchain rather than a dedicated linter configuration.

API Design Kingpin’s defining characteristic is its fluent, chainable declaration style that reads like a sentence and yields a directly usable typed variable at definition time, paired with automatically generated and template-customizable help output and shell-completion scripts with no extra setup. These ergonomic ideas were notably ahead of their contemporaries when introduced, though the project’s own README now points newcomers toward the same author’s newer, lighter successor library, so the design is better described as an influential precedent than as cutting-edge today.

Used by 5 apps in this directory

Go
97%
Apache 2.0

kopia

File Storage

14,209

Fast, encrypted, deduplicated backups to any cloud or local storage with full client-side control.

View details
91
Repo Health
83
Technical
68
Dependency
Built with
Go 97%
Updated 6 days ago
TypeScript
51%
ZLIB

Portainer

Devops

38,590

A lightweight, open-source web UI that puts Docker, Kubernetes, and Podman management within reach of any team—no CLI expertise required.

View details
92
Repo Health
79
Technical
65
Dependency
Built with
TypeScript 51%
Go 38%
Updated 1 weeks ago
Go
90%
AGPL 3.0

Pyroscope

Developer Tools · Devops · Monitoring

11,678

An open-source, horizontally scalable continuous profiling platform that pinpoints CPU, memory, and I/O bottlenecks down to the exact line of code, built by Grafana Labs alongside Loki, Tempo, and Mimir.

View details
91
Repo Health
89
Technical
65
Dependency
Built with
Go 90%
Updated 1 weeks ago
Go
75%
AGPL 3.0

Teleport

Authentication · Security

20,950

Zero-trust infrastructure access platform that replaces credentials and VPNs with short-lived certificates, SSO, and identity-aware proxies for SSH, Kubernetes, databases, RDP, and AI agents.

View details
93
Repo Health
81
Technical
68
Dependency
Built with
Go 75%
TypeScript 16%
Updated 2 weeks ago
Go
98%
Other

Tyk API Gateway

Developer Tools · Devops

10,838

Cloud-native, high-performance open-source API gateway for REST, GraphQL, gRPC, and TCP — built in Go since 2014 with no feature lockout.

View details
96
Repo Health
78
Technical
66
Dependency
Built with
Go 98%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers