Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add two new ArgumentArrayParsingStrategy options #496

Merged

Conversation

natecook1000
Copy link
Member

@natecook1000 natecook1000 commented Sep 22, 2022

Description

This adds two new parsing options for argument arrays, and renames .unconditionalRemaining to .captureForPassthrough:

  • unconditionalRemaining has been an attractive nuisance. It looks like it means "everything leftover", but it actually has a specific and slightly strange set of behaviors to support SwiftPM capturing inputs to pass on to a sub-client, as in swift run MyExecutableTarget. The new name better matches this intended usage.
  • allUnrecognized collects all the inputs that weren't used during parsing, which is a more generally useful behavior. This essentially suppresses all "unrecognized flag/option" and "unexpected argument" errors, and makes those extra inputs available to the client.
  • postTerminator collects all inputs that follow the -- terminator, before trying to parse any other positional arguments. This is a non-standard, but sometimes useful parsing strategy.

Detailed Design

Two new symbols and one renaming — see the diff for full API documentation.

/// After parsing, capture all unrecognized inputs in this argument array.
public static var allUnrecognized: ArgumentArrayParsingStrategy {
  self.init(base: .allUnrecognized)
}

/// Before parsing, capture all inputs that follow the `--` terminator in this
/// argument array.
public static var postTerminator: ArgumentArrayParsingStrategy {
  self.init(base: .postTerminator)
}

/// Parse all remaining inputs after parsing any known options or flags,
/// including dash-prefixed inputs and the `--` terminator.
public static var captureForPassthrough: ArgumentArrayParsingStrategy {
  self.init(base: .allRemainingInput)
}

@available(*, deprecated, renamed: "captureForPassthrough")
public static var unconditionalRemaining: ArgumentArrayParsingStrategy {
  .captureForPassthrough
}

Documentation Plan

Includes API documentation for the new symbols and significantly expanded docs for the existing members.

Test Plan

Includes unit tests for the new cases.

Source Impact

This deprecates the unconditionalRemaining strategy, which was confusingly named. The new name is captureForPassthrough, which is more explicit about its intent.

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

This adds two new parsing options for argument arrays, and renames
`.unconditionalRemaining` to `.captureForPassthrough`.

- `.allUnrecognized` collects all the inputs that weren't used during
parsing. This essentially suppresses all "unrecognized flag/option"
and "unexpected argument" errors, and makes those extra inputs
available to the client.
- `.postTerminator` collects all inputs that follow the `--`
terminator, before trying to parse any other positional arguments.
This is a non-standard, but sometimes useful parsing strategy.
@natecook1000 natecook1000 marked this pull request as ready for review September 30, 2022 21:21
@natecook1000
Copy link
Member Author

@swift-ci Please test

@natecook1000
Copy link
Member Author

@swift-ci Please test

@natecook1000 natecook1000 merged commit a8b48bc into apple:main Oct 7, 2022
@danpalmer
Copy link

@natecook1000 Thanks for implementing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants