Skip to content

Confusing error output when passing a single-dash unknown option that contains some valid short label option names #709

@jamieQ

Description

@jamieQ

see relevant discussion on the swift forums here: https://forums.swift.org/t/why-does-swift-treat-double-dash-command-line-arguments-differently/77727/8

ArgumentParser version:
main branch (commit: a01856b)
Swift version:
swift-driver version: 1.115 Apple Swift version 6.0.2 (swiftlang-6.0.2.1.2 clang-1600.0.26.4)
Target: arm64-apple-macosx14.0

Checklist

Steps to Reproduce

run this test case in ParsableArgumentsValidationTests:

extension ParsableArgumentsValidationTests {
    func test_shouldMaybeProduceUnknownOptionErrorInsteadOfMissingValue() throws {
      struct SomeArgs: ParsableArguments {
        @Option(name: .shortAndLong)
        var x_arg: Int

        @Option(name: .shortAndLong)
        var z_arg: Int
      }

      // swap order of 'x' and 'z' in the string to get different error output
      AssertErrorMessage(
        SomeArgs.self,
        [
          "-should_maybe_be_an_unknown_option_error_but_is_a_missing_value_error_when_it_includes_x_or_z",
        ],
        "Unknown option '-should_maybe_be_an_unknown_option_error_but_is_a_missing_value_error_when_it_includes_x_or_z'"
      )
      // actually: "Missing value for '-x <x_arg>'"
    }
}

Expected behavior

an error indicating the given option is unrecognized

Actual behavior

an error is produced suggesting that the option name is valid but is missing a value

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions