apple / swift-argument-parser
git clone https://github.com/apple/swift-argument-parser.git
1.8.2 · 4mo ago
🔥 on GitHub Trending today
Straightforward, type-safe argument parsing for Swift
—
stars, 24h
+8
stars, 7 days · #1,586
—
stars, 30 days
3.8k
★ total · +0% this week
432
forks · 156 open issues
Star history starts 2026-10-20; the chart appears after the second daily snapshot.
LanguageSwift
LicenseApache-2.0
Created2020-02-20 (6y ago)
Last pushtoday
Watchers149
OwnerOrganization
Seen on GitHub Trending
- 2026-10-20 — #9 weekly in swift · +8 ★
GitHub topics
Links
- GitHub: github.com/apple/swift-argument-parser
- Homepage: https://swiftpackageindex.com/apple/swift-argument-parser/documentation
- Releases · Issues · Hacker News mentions
README excerpt
# Swift Argument Parser ## Usage Begin by declaring a type that defines the information that you need to collect from the command line. Decorate each stored property with one of `ArgumentParser`'s property wrappers, and then declare conformance to `ParsableCommand` and add the `@main` attribute. (Note, for `async` renditions of `run`, conform to `AsyncParsableCommand` rather than `ParsableCommand`.) Finally, implement your command's logic in the `run()` method. [code] The `ArgumentParser` library parses the command-line arguments, instantiates your command type, and then either executes your `run()` method or exits with a useful message. `ArgumentParser` uses your properties' names and type information, along with the details you provide using property wrappers, to supply useful error messages and detailed help: [code] ## Documentation For guides, articles, and API documentation see the [library's documentation on the Web][docs] or in Xcode. - [ArgumentParser documentation][docs] - Getting Started with ArgumentParser - `ParsableCommand` documentation - `AsyncParsableCommand` documentation [docs]: https://swiftpackageindex.com/apple/swift-argument-parser/documentation/argumentparser #### Examples This repository includes a few examples of using the library: - `repeat` is the example shown above. - `roll` is a simple utility implemented as a straight-line script. - `math` is an annotated example of using nested commands and subcommands. - `count-lines` uses `async`/`await` code in its implementation. - `default-as-flag` demonstrates hybrid options that can work both as flags and as options with values. You can also see examples of `ArgumentParser` adoption among Swift project tools: - `swift-format` uses some advanced features, like custom option values and hidden flags. - `swift-package-manager` includes a deep command hierarchy and extensive use of option groups. ## Project Status The Swift Argument Parser package is source-stable; version numbers follow semantic versioning. Source-breaking changes to public API can only land in a new major version. The public API of version 1.0.0 of the `swift-argument-parser` package consists of non-underscored declarations that are marked public in the `ArgumentParser` module. Interfaces that aren't part of the public API may continue to change in any release, including the exact wording and formatting of the autogenerated help and error messages, as well as the package’s examples, tests, utilities, and documentation. Future minor versions of the package may introduce changes to these rules as needed. We want this package to quickly embrace Swift language and toolchain improvements that are relevant to its mandate. Accordingly, from time to time, we expect that new versions of this package will require clients to upgrade to a more recent Swift toolchain release. Requiring a new Swift release will only require a minor version bump. ## Adding `ArgumentParser` as a Dependency To use the `ArgumentParser` libra