Skip to content

@Argument String arrays with .unconditionalRemaining repeat arguments #88

@glessard

Description

@glessard

When using an @Argument that parses to a [String] using the .unconditionalRemaining parsing strategy, command-line arguments that start with "--", "/", "+" and such behave as expected. However an argument that starts with a single dash ("-") appears to be appended to the array as many times as it has characters — as long as the 2nd character isn't also "-".

ArgumentParser version:
81b8064dbd99cf75a4734fa64efe5e680d0b4d9c
Swift version:
Apple Swift version 5.2 (swiftlang-1103.0.30 clang-1103.0.30)
Target: x86_64-apple-darwin19.3.0

Checklist

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

Steps to Reproduce

Using this simple program:

import ArgumentParser
public struct Options: ParsableCommand {
  @Argument(parsing: .unconditionalRemaining) public var arguments: [String]
}

let options = Options.parseOrExit()
print(options.arguments)
$ swift run options
[]
$ swift run options blah -a
["blah", "-a"]
$ swift run options blah -a -bb -ccc --dddd

Expected behavior

For the third command from above, I expected the output to be:
["blah", "-a", "-bb", "-ccc", "--dddd"]

Actual behavior

The output is actually:
["blah", "-a", "-bb", "-bb", "-bb", "-ccc", "-ccc", "-ccc", "-ccc", "--dddd"]

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions