ArgumentParser helps Swift developers define command-line tools with structured types, property wrappers, and automatic help and error messages.
Overview
Swift Argument Parser is a library for building command-line interfaces in Swift. You declare a type that holds the data to collect from the shell, mark fields with Argument, Option, and Flag wrappers, and conform to ParsableCommand or AsyncParsableCommand for asynchronous run methods.
At runtime the library reads argv, constructs your command type, and either invokes run() or exits with guidance. It uses property names, types, and wrapper settings to produce help text and parsing errors.
Nested subcommands, custom validation, shell completion scripts, and manual parsing for tests are supported. Documentation covers essentials, customizing help, and advanced parsing topics.
The package is distributed via Swift Package Manager for command-line executable targets. Other Swift tooling projects have adopted it for their own CLIs.
Key features
- ParsableCommand and AsyncParsableCommand
- Argument, Option, and Flag property wrappers
- Nested commands and subcommands
- Custom validation and error types
- Autogenerated help and usage text
- Shell completion script generation
- ExpressibleByArgument and EnumerableFlag
- Manual parsing for testing
Use cases
- Swift CLI utilities and scripts
- Multi-subcommand developer tools
- Async command-line workflows
- Tools needing rich --help output