---
title: ArgumentParser
description: Straightforward, type-safe argument parsing for Swift.
source: https://apple.github.io/swift-argument-parser/documentation/argumentparser/
timestamp: 2026-05-28T11:32:58.852Z
---

**Framework**

# ArgumentParser

> Straightforward, type-safe argument parsing for Swift.

## Overview

By using `ArgumentParser`, you can create a command-line interface tool by declaring simple Swift types. 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, declare conformance to [Parsable Command](/external/https://apple.github.io/swift-argument-parser/documentation/argumentparser/parsablecommand), and implement your command’s logic in its `run()` method.

```swift
import ArgumentParser

@main
struct Repeat: ParsableCommand {
    @Argument(help: "The phrase to repeat.")
    var phrase: String

    @Option(help: "The number of times to repeat 'phrase'.")
    var count: Int? = nil

    mutating func run() throws {
        let repeatCount = count ?? 2
        for _ in 0..<repeatCount {
            print(phrase)
        }
    }
}
```

When a user executes your command, the `ArgumentParser` library parses the command-line arguments, instantiates your command type, and then either calls your `run()` method or exits with a useful message.

![The output of the Repeat command, declared above.](/images/repeat.png)

#### Additional Resources

- [](https://github.com/apple/swift-argument-parser/)
- [60](https://forums.swift.org/c/related-projects/argumentparser/60)

## Essentials

- [Getting Started with ArgumentParser](/external/https://apple.github.io/swift-argument-parser/documentation/argumentparser/gettingstarted) Learn to set up and customize a simple command-line tool.
- [ParsableCommand](/external/https://apple.github.io/swift-argument-parser/documentation/argumentparser/parsablecommand) A type that can be executed as part of a nested tree of commands.
- [AsyncParsableCommand](/external/https://apple.github.io/swift-argument-parser/documentation/argumentparser/asyncparsablecommand) A type that can be executed asynchronously, as part of a nested tree of commands.
- [Defining Commands and Subcommands](/external/https://apple.github.io/swift-argument-parser/documentation/argumentparser/commandsandsubcommands) Break complex command-line tools into a tree of subcommands.
- [Customizing Help for Commands](/external/https://apple.github.io/swift-argument-parser/documentation/argumentparser/customizingcommandhelp) Define your command’s abstract, extended discussion, or usage string, and set the flags used to invoke the help display.

## Arguments, Options, and Flags

- [Declaring Arguments, Options, and Flags](/external/https://apple.github.io/swift-argument-parser/documentation/argumentparser/declaringarguments) Use the ,  and  property wrappers to declare the command-line interface for your command.
- [Argument](/external/https://apple.github.io/swift-argument-parser/documentation/argumentparser/argument) A property wrapper that represents a positional command-line argument.
- [Option](/external/https://apple.github.io/swift-argument-parser/documentation/argumentparser/option) A property wrapper that represents a command-line option.
- [Flag](/external/https://apple.github.io/swift-argument-parser/documentation/argumentparser/flag) A property wrapper that represents a command-line flag.
- [OptionGroup](/external/https://apple.github.io/swift-argument-parser/documentation/argumentparser/optiongroup) A wrapper that transparently includes a parsable type.
- [ParsableArguments](/external/https://apple.github.io/swift-argument-parser/documentation/argumentparser/parsablearguments) A type that can be parsed from a program’s command-line arguments.

## Property Customization

- [Customizing Help](/external/https://apple.github.io/swift-argument-parser/documentation/argumentparser/customizinghelp) Support your users (and yourself) by providing rich help for arguments, options, and flags.
- [ArgumentHelp](/external/https://apple.github.io/swift-argument-parser/documentation/argumentparser/argumenthelp) Help information for a command-line argument.
- [ArgumentVisibility](/external/https://apple.github.io/swift-argument-parser/documentation/argumentparser/argumentvisibility) Visibility level of an argument’s help.
- [NameSpecification](/external/https://apple.github.io/swift-argument-parser/documentation/argumentparser/namespecification) A specification for how to represent a property as a command-line argument label.

## Custom Types

- [ExpressibleByArgument](/external/https://apple.github.io/swift-argument-parser/documentation/argumentparser/expressiblebyargument) A type that can be expressed as a command-line argument.
- [EnumerableFlag](/external/https://apple.github.io/swift-argument-parser/documentation/argumentparser/enumerableflag) A type that represents the different possible flags to be used by a  property.

## Validation and Errors

- [Providing Custom Validation](/external/https://apple.github.io/swift-argument-parser/documentation/argumentparser/validation) Provide helpful feedback to users when things go wrong.
- [ValidationError](/external/https://apple.github.io/swift-argument-parser/documentation/argumentparser/validationerror) An error type that is presented to the user as an error with parsing their command-line input.
- [CleanExit](/external/https://apple.github.io/swift-argument-parser/documentation/argumentparser/cleanexit) An error type that represents a clean (i.e. non-error state) exit of the utility.
- [ExitCode](/external/https://apple.github.io/swift-argument-parser/documentation/argumentparser/exitcode) An error type that only includes an exit code.

## Shell Completion Scripts

- [Generating and Installing Completion Scripts](/external/https://apple.github.io/swift-argument-parser/documentation/argumentparser/installingcompletionscripts) Install shell completion scripts generated by your command-line tool.
- [Customizing Completions](/external/https://apple.github.io/swift-argument-parser/documentation/argumentparser/customizingcompletions) Provide custom shell completions for your command-line tool’s arguments and options.
- [CompletionKind](/external/https://apple.github.io/swift-argument-parser/documentation/argumentparser/completionkind) The type of completion to use for an argument or option.

## Advanced Topics

- [Manual Parsing and Testing](/external/https://apple.github.io/swift-argument-parser/documentation/argumentparser/manualparsing) Provide your own array of command-line inputs or work directly with parsed command-line arguments.
- [Experimental Features](/external/https://apple.github.io/swift-argument-parser/documentation/argumentparser/experimentalfeatures) Learn about ArgumentParser’s experimental features.

---

*Extracted by [sosumi.ai](https://sosumi.ai) - Making Apple docs AI-readable.*
*This is unofficial content. All documentation belongs to Apple Inc.*
