Argument

A property wrapper that represents a positional command-line argument.

Argument.swift:45Argument.md
@propertyWrapper struct Argument<Value>

Use the @Argument wrapper to define a property of your custom command as a positional argument. A positional argument for a command-line tool is specified without a label and must appear in declaration order. @Argument properties with Optional type or a default value are optional for the user of your command-line tool.

For example, the following program has two positional arguments. The name argument is required, while greeting is optional because it has a default value.

@main
struct Greet: ParsableCommand {
    @Argument var name: String
    @Argument var greeting: String = "Hello"

    mutating func run() {
        print("\(greeting) \(name)!")
    }
}

You can call this program with just a name or with a name and a greeting. When you supply both arguments, the first argument is always treated as the name, due to the order of the property declarations.

$ greet Nadia
Hello Nadia!
$ greet Tamara Hi
Hi Tamara!

Single Arguments

Array Arguments

Infrequently Used APIs