Swift Argument Parser
Documentation
For guides, articles, and API documentation see the library’s documentation on the Web or in Xcode.
- ArgumentParser documentation
- Getting Started with ArgumentParser
ParsableCommand
documentationAsyncParsableCommand
documentation
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
usesasync
/await
code in its implementation.
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
library in a SwiftPM project,
add it to the dependencies for your package and your command-line executable target:
let package = Package(
// name, platforms, products, etc.
dependencies: [
// other dependencies
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.3.0"),
],
targets: [
.executableTarget(name: "<command-line-tool>", dependencies: [
// other dependencies
.product(name: "ArgumentParser", package: "swift-argument-parser"),
]),
// other targets
]
)