Repolode
apple

apple/swift-argument-parser

A type-safe Swift library for declaring and parsing command-line arguments, options, and flags with auto-generated help.

Stars
3,793
Forks
438
Open issues
154
Last commit
3 days ago

What is it?

Swift Argument Parser is a library for building command-line tools in Swift. You declare a type whose stored properties are annotated with property wrappers for flags, options, and positional arguments, then conform it to ParsableCommand or AsyncParsableCommand. The library parses the arguments, instantiates your type, and runs your run() method, or exits with an error message.

Because the parser uses property names, types, and the help text you supply, it generates usage lines, detailed --help output, and error messages without extra code. Commands can be nested into subcommands, and the package includes examples such as a nested math tool and an async/await line counter.

The package follows semantic versioning and requires a minimum Swift toolchain that depends on the release, from Swift 5.1 for early versions up to Swift 6.0 for 1.8.0 and later.

Key features

  • 01Declare flags, options, and positional arguments with property wrappers.
  • 02Generates usage text, detailed help, and error messages automatically.
  • 03Supports nested commands and subcommands.
  • 04Offers async/await support through AsyncParsableCommand.
  • 05Integrates with Swift Package Manager as a dependency.

Use cases

  • Building a command-line tool in Swift or on Apple platforms.
  • Adding a structured subcommand hierarchy to an existing Swift CLI.
  • Writing a quick script-style utility that needs typed argument parsing.

Quick start

  1. 1

    Add the ArgumentParser package to your Package.swift dependencies and your executable target

  2. 2

    Declare a type that conforms to ParsableCommand, add the @main attribute, and implement run()

Things to know

  • Versions 1.8.0 and later require Swift 6.0 or newer.
  • Autogenerated help and error message wording may change in any release.

Topics

FAQ

What is swift-argument-parser?
A type-safe Swift library for declaring and parsing command-line arguments, options, and flags with auto-generated help. Swift Argument Parser is a library for building command-line tools in Swift. You declare a type whose stored properties are annotated with property wrappers for flags, options, and positional arguments, then conform it to ParsableCommand or AsyncParsableCommand. The library parses the arguments, instantiates your type, and runs your run() method, or exits with an error message.
Is swift-argument-parser free to use? What license does it have?
swift-argument-parser is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
Is swift-argument-parser still maintained?
Actively maintained. The last commit to swift-argument-parser was on Oct 16, 2026.
What can I use swift-argument-parser for?
Building a command-line tool in Swift or on Apple platforms. Adding a structured subcommand hierarchy to an existing Swift CLI. Writing a quick script-style utility that needs typed argument parsing.
How do I install swift-argument-parser?
Add the ArgumentParser package to your Package.swift dependencies and your executable target Declare a type that conforms to ParsableCommand, add the @main attribute, and implement run()
Where can I get swift-argument-parser?
The source code and installation instructions are on GitHub: https://github.com/apple/swift-argument-parser

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects