Skip to content

Add native response file support#909

Draft
bkhouri wants to merge 1 commit into
mainfrom
t/main/gh846_native_response_file_support
Draft

Add native response file support#909
bkhouri wants to merge 1 commit into
mainfrom
t/main/gh846_native_response_file_support

Conversation

@bkhouri

@bkhouri bkhouri commented May 27, 2026

Copy link
Copy Markdown
Contributor

Add native response file support in Swift Argument Parser for all ParsableCommand and AsyncParsableCommand commands.

Fixes: #846

Checklist

  • I've added at least one test that validates that my change is working, if appropriate
  • I've followed the code style of the rest of the project
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary

### Quoted Arguments

Response files support quoted arguments for values containing spaces:

@cmcgee1024 cmcgee1024 May 28, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: quoting brings up the question of how escaping works for things like spaces in unquoted text, and escaping the quotes themselves. If you intend on using shell conventions, then what about single quotes, or escaping scapes with \?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#41 has some links to how this is supported by some other languages/packages - some of them let one control the support the files will support.

Since someone could be using this support to migrate a tool to Swift, they might need the quoted form while some other migration might need the shell escaping support.

Likewise for what the marker on the command line is to say a file is a params/response file. So it if the leading @ maybe should be configurable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documents has been updated to provide additional information on the quotes arguments.


### Nested Response Files

Response files can reference other response files:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Maybe don't add nesting unless there's a compelling workflow to do so. By having response files it alleviates the problem of command lines that are too long for the OS, improves versioning, and clarity. I'm not sure if nesting adds much beyond that, and brings more levels of indirection for the user to figure out where an argument came from.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LLVM's response file parsing supports nesting. I know that swift-driver today uses its own parsing instead of swift-argument-parser, but if there's any desire in the future to move existing LLVM-based tools from C++ onto Swift using swift-argument-parser, we'd need nested response file support to keep parity.

IMO, we should support it unless there's a compelling reason not to, to avoid unnecessary limitations on what the library can do. It looks like it falls out naturally from the implementation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change currently supports nested response file.


## Literal At Signs

To use a literal `@` character in an argument, escape it with `@@`:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: it is good to call this kind of escaping out like this.

Comment thread Sources/ArgumentParser/Documentation.docc/Articles/ResponseFiles.md
@rauhul

rauhul commented May 28, 2026

Copy link
Copy Markdown
Collaborator

IMO this sort of feature will need to come with some sort of source location feature too

@bkhouri bkhouri force-pushed the t/main/gh846_native_response_file_support branch 11 times, most recently from 34c2c7d to c4a089d Compare July 10, 2026 18:46
Add native response file support in Swift Argument Parser for all
`ParsableCommand` and `AsyncParsableCommand` commands.

Since the nested response files are supported, also include an
experiemental command line argument that provides source location
support.

Fixes: #846
@bkhouri bkhouri force-pushed the t/main/gh846_native_response_file_support branch from c4a089d to 5cf5af6 Compare July 10, 2026 19:09
@bkhouri

bkhouri commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

IMO this sort of feature will need to come with some sort of source location feature too

Thanks for this feedback. A source location feature has been added.

@bkhouri bkhouri marked this pull request as ready for review July 10, 2026 19:23
@bkhouri bkhouri marked this pull request as draft July 10, 2026 19:24
@bkhouri

bkhouri commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

marking as Draft to prevent accidentally merging before it's ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

5 participants