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

postTerminator: Either confusing documentation or wrong behavior #597

Closed
2 tasks done
Jean-Daniel opened this issue Nov 13, 2023 · 1 comment · Fixed by #621
Closed
2 tasks done

postTerminator: Either confusing documentation or wrong behavior #597

Jean-Daniel opened this issue Nov 13, 2023 · 1 comment · Fixed by #621
Labels
documentation Improvements or additions to documentation

Comments

@Jean-Daniel
Copy link

The postTerminator documentation stats:

Before parsing, capture all inputs that follow the -- terminator

But in reality, that step is performed before parsing Arguments, but after parsing Options.

I have the following code:

struct MyCommand: ParsableCommand {
  @Option(parsing: .remaining) var sshArgs: [String] = []
  @Argument(parsing:.postTerminator) var remoteCommand: [String] = []


}

I'm trying to parse the following command line:

mytool --ssh-args -c -p 2023 -O -f "some file" -- echo "Hello World"

and get sshArgs = [ "-c", "-p", "2023", "-O", "-f", "some file"]
and remoteCommand = [ "echo", "Hello World" ]

If the documentation was accurate, remoteCommand should be performed first and capture echo "Hello World".

So, this is either the expected behavior, and the documentation requires some clarification, or the documentation is right, and postTerminator parsing is broken.

ArgumentParser version: 1.23

Swift version: swift-driver version: 1.87.1 Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1)

Checklist

  • If possible, I've reproduced the issue using the main branch of this package
  • I've searched for existing GitHub issues

Steps to Reproduce

@main
struct MyCommand: ParsableCommand {
  @Option(parsing: .remaining) var sshArgs: [String] = []
  @Argument(parsing:.postTerminator) var remoteCommand: [String] = []
 
  public func run() {
    print(sshArgs)
    print(remoteCommand)
  }
}

Expected behavior

sshArgs contains arguments before the terminator, and remoteCommands the arguments after the terminator.

Actual behavior

sshArgs contains everything, including the terminator.

@natecook1000 natecook1000 added the documentation Improvements or additions to documentation label Nov 27, 2023
@natecook1000
Copy link
Member

Thanks for the report, @Jean-Daniel! At this point, I think this needs to be treated as a documentation error, given that the behavior you've documented here has existed for some time, and is needed to support pass-through situations, where a command needs to capture the remainder of an input, regardless of what's there.

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

Successfully merging a pull request may close this issue.

2 participants