Skip to content
FossShelf
Home / Categories / For Engineers

Swift Argument Parser

Type-safe CLI argument parsing for Swift

Replaces —

3.81K starsApache-2.0last commit 13 Nov 2026

Who it's for

Developer tools and automation scripts

Swift developers building internal build tools, code generators, or developer-facing CLI utilities get typed argument handling and polished help output without manual parsing code.

Swift Package Manager plugins

SPM command plugins receive arguments from the package manager and pass them to the plugin entry point. swift-argument-parser is the standard way to parse those arguments inside a plugin.

Not building an SPM plugin

Server-side Swift services with admin CLIs

Server-side Swift applications that expose maintenance commands, migration runners, or admin utilities can use swift-argument-parser to build a consistent CLI layer alongside their server code.

Not using Swift on the server

macOS system utilities

Native macOS command-line utilities that need to accept flags and options from the terminal can use swift-argument-parser to match the conventions of standard Unix tools with minimal code.

The problem

Writing CLI argument parsing by hand in Swift means duplicating logic for validation, error messages, and help text across every tool. Keeping the help output in sync with actual behaviour is tedious and error-prone, and adding subcommands or optional arguments multiplies that work.

How it works

Property wrapper inputs

Declare CLI inputs as struct properties with @Argument, @Option, or @Flag. The library reads the property types and annotations to drive parsing, so there is no separate schema to maintain.

Auto-generated help and error messages

Help text, usage lines, and argument-error messages are generated from property names and help strings. Running --help always reflects the actual struct definition.

Subcommand composition

Nest ParsableCommand types to build multi-level CLIs. The library routes to the correct subcommand and generates combined help output for the full command tree.

Async command support

Commands can conform to AsyncParsableCommand instead of ParsableCommand, allowing run() to be an async function and use Swift structured concurrency.

Flexible option naming

Options support short names, long names, or combined short-and-long names via the name parameter. Custom names can be provided for any property.

Source-stable semantic versioning

The library follows semantic versioning. Source-breaking public API changes are reserved for new major versions, making it safe to adopt in long-lived tools.

Features

  • Property wrapper inputs
  • Auto-generated help and error messages
  • Subcommand composition
  • Async command support
  • Flexible option naming
  • Source-stable semantic versioning

How to install

// Package.swift .package(url: "https://github.com/apple/swift-argument-parser", from: "1.7.0") // In your target dependencies: .product(name: "ArgumentParser", package: "swift-argument-parser")

Recommended for this setup

Strengths

  • First-party Apple library: Maintained by Apple and used in their own tools, including swift-package-manager and swift-format. This gives confidence in long-term maintenance and compatibility with new Swift releases.
  • Zero boilerplate parsing loop: There is no manual argv loop or switch statement. Conforming to ParsableCommand and adding property wrappers is all that is needed; the library handles the rest including exit codes.
  • Rich error output out of the box: Missing required arguments, wrong types, and unrecognised flags all produce informative error messages naming the problematic input, without any extra error-handling code.
  • Integrates via Swift Package Manager: Adding the package is a single dependency line in Package.swift. No additional tooling, build scripts, or code generation steps are required.

Trade-offs

  • Swift only: swift-argument-parser is a Swift library and cannot be used from other languages. Teams not using Swift will need a different CLI parsing library.
  • Swift 6.0 required for latest releases: Version 1.8.0 and later require Swift 6.0. Projects constrained to older Swift versions must pin to an earlier release, which may not receive new features or fixes.
  • Not a standalone CLI framework: The library handles argument parsing only. Features like interactive prompts, progress bars, colour output, or terminal manipulation require additional libraries.

Tech stack

Languages
Swift, Shell, Roff, CMake
Frameworks
—
Databases
—
Tooling
—

FAQ

How do I add swift-argument-parser to my project?

Add `.package(url: "https://github.com/apple/swift-argument-parser", from: "1.7.0")` to the dependencies in your Package.swift, then add `"ArgumentParser"` to your executable target's dependencies array.

What is the difference between @Argument, @Option, and @Flag?

@Argument is a positional value read directly from the command line. @Option is a named value passed with a flag like --count 3. @Flag is a boolean switch that is true when present and false when absent.

Can I use async/await in my command's run method?

Yes. Conform your command to AsyncParsableCommand instead of ParsableCommand and mark run() as async. This lets you call async APIs directly inside the command.

How do I build a CLI with subcommands?

Define a root ParsableCommand with a static var configuration that includes a subcommands array listing other ParsableCommand types. Each subcommand defines its own properties and run() method.

What Swift version is required?

Version 1.8.0 and later require Swift 6.0. If you are on Swift 5.7 through 5.9, use a release in the 1.3.0 to 1.7.x range. Earlier Swift versions require older releases; the compatibility table is in the repository README.

Similar tools

More in Engineers