Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Add new items at the end of the relevant section under **Unreleased**.
### Additions

- `CommandConfiguration` now accepts a `helpBanner`, a string printed verbatim above the overview on a command's help screen and inherited by its subcommands unless they provide their own banner or the empty string.
- Commands can now opt in to response-file expansion by setting the `responseFilePrefix` property on their `CommandConfiguration` to the character that should introduce a response-file reference (for example, `static let configuration = CommandConfiguration(responseFilePrefix: "@")`). The property defaults to `nil`, meaning response-file expansion is disabled unless the root command opts in.

---

Expand Down
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,32 @@ OPTIONS:
-h, --help Show help for this command.
```

## Response Files

Swift Argument Parser can expand response files, letting you store command-line arguments in text files. This is especially useful for commands with many arguments or for reusable configurations. Opt in on your root command by setting the `responseFilePrefix` property in its `CommandConfiguration` to the character that should introduce a response-file reference (commonly `@`):

```swift
struct Repeat: ParsableCommand {
static let configuration = CommandConfiguration(responseFilePrefix: "@")
// ...
}
```

```bash
# Store arguments in a file
$ echo "--count 5 --include-counter hello" > args.txt

# Use the response file with @filename syntax
$ repeat @args.txt
1: hello
2: hello
3: hello
4: hello
5: hello
```

Response files support multiple formats, comments, quoted arguments, and can even reference other response files. See the [Response Files documentation](https://swiftpackageindex.com/apple/swift-argument-parser/documentation/argumentparser/responsefiles) for complete details.

## Documentation

For guides, articles, and API documentation see the
Expand Down
1 change: 1 addition & 0 deletions Sources/ArgumentParser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ add_library(ArgumentParser
Parsing/Parsed.swift
Parsing/ParsedValues.swift
Parsing/ParserError.swift
Parsing/ResponseFileExpander.swift
Parsing/SplitArguments.swift

Usage/DumpHelpGenerator.swift
Expand Down
5 changes: 3 additions & 2 deletions Sources/ArgumentParser/Documentation.docc/ArgumentParser.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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 ``ParsableCommand``,
and implement your command's logic in its `run()` method.
and implement your command's logic in its `run()` method.
For `async` renditions of `run`, declare ``AsyncParsableCommand`` conformance instead.

```swift
Expand All @@ -33,7 +33,7 @@ struct Repeat: ParsableCommand {
}
```

When a user executes your command,
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.
Expand All @@ -58,6 +58,7 @@ and then either calls your `run()` method or exits with a useful message.
### Arguments, Options, and Flags

- <doc:DeclaringArguments>
- <doc:ResponseFiles>
- ``Argument``
- ``Option``
- ``Flag``
Expand Down
Loading