tinyflags
A minimal, extensible CLI flag-parsing library for Go.
Tinyflags provides typed flags, fluent builders, environment-variable overrides, subcommands and configurable help output without third-party runtime dependencies.
go get github.com/containeroo/tinyflags
Features
- Short & long flags (
-d,--debug) - Boolean strict mode (
--flag=true/false) - Environment variable overrides (
EnvPrefix, per-flag opt-out) - Value provenance (exact
-x/--longflag spelling or environment-variable key) - Required, deprecated, and grouped flags
- Slice flags (
[]T) with custom delimiters - Allowed choices, validation and finalizers
- One Of groups
- All or None groups
- Custom placeholders & help sections
- Dynamic flags (
--group.id.field=value) - Nested commands and typed runners
- Typed values (
*os.File,*net.TCPAddr,*url.URL,time.Duration, etc.)
Why yet another flag library?
-
Validate and finalize on the fly Tinyflags lets you validate and finalize values as they are parsed, so input shaping and business rules can live directly on the flag definition.
-
Group-aware constraints Tinyflags includes built-in one-of and all-or-none groups, plus per-flag dependency rules like
Requires(...). -
Built-in help and version handling
--helpand--versionare supported out of the box, including library-friendly error sentinels for callers that want to intercept them. -
Dynamic flags Tinyflags supports
--group.id.field=valueflags whereidis only known at parse time, so one parser can handle both regular and instance-scoped settings.
In short, tinyflags aims to reduce flag boilerplate while keeping the parser predictable, typed, and easy to extend.
Documentation
- Getting started: install tinyflags and parse your first CLI.
- Flags and types: scalars, slices, enums and fluent flag builders.
- Commands: nested subcommands, global flags and typed runners.
- Parsing and positional arguments: precedence, positional constraints and parse errors.
- Environment variables: automatic and explicit bindings.
- Dynamic flags: instance-scoped configuration and custom slices.
- Validation and finalization: reusable validators and value transformations.
- Flag groups: mutually exclusive and require-together options.
- Value provenance: inspect explicit overrides and mask secrets.
- Help and API reference: help layout and API tables.
- Examples: runnable examples in the repository.