whatisgithub

What is swift-argument-parser?

apple/swift-argument-parser — explained in plain English

Analysis updated 2026-07-03

3,704SwiftAudience · developerComplexity · 2/5Setup · easy

In one sentence

An Apple-made Swift library for building command-line tools that parse user input automatically, you describe your expected flags and arguments as a data structure and the library handles the rest, including error messages and help text.

Mindmap

mindmap
  root((swift-argument-parser))
    What it does
      Parses CLI arguments
      Type-safe Swift structs
      Auto error messages
    Input types
      Flags (true or false)
      Options with values
      Positional arguments
    Features
      Auto-generated help text
      Subcommand support
      Stable versioned API
    Setup
      Swift Package Manager dep
      Annotate struct properties
      Used by Apple internally
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Build a Swift command-line tool that accepts flags and options from the terminal without writing manual argument-parsing code

USE CASE 2

Add subcommands to a CLI tool in Swift, such as separate add and remove modes, each with their own options

USE CASE 3

Generate automatic help text for a Swift CLI tool from the descriptions you attach to each argument

USE CASE 4

Add Swift Argument Parser to a Swift Package Manager project to handle user input for a build or automation script

What is it built with?

SwiftSwift Package Manager

How does it compare?

apple/swift-argument-parsergee1k/upicramotion/swift-ui-animation-components-and-libraries
Stars3,7043,7013,711
LanguageSwiftSwiftSwift
Setup difficultyeasyeasymoderate
Complexity2/52/52/5
Audiencedeveloperwriterdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 30min
License information was not described in the explanation.

So what is it?

Swift Argument Parser is a library made by Apple that helps developers build command-line tools in the Swift programming language. When you write a program that runs in a terminal and accepts options or arguments from the user, you need code to read and interpret whatever the user typed. This library handles that work for you in a way that takes advantage of Swift's type system. The way you use it is by describing your command-line interface as a data structure. You define a type with properties for each piece of input you expect, annotate those properties with labels that indicate whether each one is a flag, an option with a value, or a positional argument, and the library takes care of reading from the terminal, converting values to the right types, and generating useful error messages if something is missing or invalid. Help text is built automatically from the descriptions you provide. The library also supports organizing a tool into subcommands. If you are building something with multiple modes, like a tool that can both add and remove things, you can model each mode as its own separate type and nest them together. Apple uses this library in its own projects, including the Swift package manager and the swift-format tool. The library follows a stable versioning policy, meaning that breaking changes to its public API can only happen in a new major version. Adding it to a Swift project is done through Swift Package Manager by listing it as a dependency in the package configuration file. The README includes several working examples of increasing complexity, from a simple script to a tool with nested subcommands, which makes it easy to understand how the pieces fit together.

Copy-paste prompts

Prompt 1
I'm building a Swift command-line tool that accepts a --name flag and a required positional file path. Show me how to define these using swift-argument-parser and add the package as a SPM dependency.
Prompt 2
Using swift-argument-parser, how do I create a CLI tool with subcommands, for example, a tool that has both an add and a remove mode, each with their own options?
Prompt 3
How do I add automatic help text descriptions to each argument in my swift-argument-parser command so users see useful info when they run my tool with --help?
Prompt 4
I want to write a Swift script that runs from the terminal and parses optional flags with default values using swift-argument-parser. Walk me through the minimum setup.

Frequently asked questions

What is swift-argument-parser?

An Apple-made Swift library for building command-line tools that parse user input automatically, you describe your expected flags and arguments as a data structure and the library handles the rest, including error messages and help text.

What language is swift-argument-parser written in?

Mainly Swift. The stack also includes Swift, Swift Package Manager.

What license does swift-argument-parser use?

License information was not described in the explanation.

How hard is swift-argument-parser to set up?

Setup difficulty is rated easy, with roughly 30min to a first successful run.

Who is swift-argument-parser for?

Mainly developer.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.