apple / apple/swift-argument-parser

Inconsistent handling of `EnumerableFlag`s & `ExpressibleByArgument `s on the command line

Open
#771 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
3.8k
Forks
411
Avg merge
7d 13h
Merged PRs (30d)
17

Description

There seems to be inconsistent handling of enum raw values on the command line.

The following code is from `CompletionScriptTests.swift`:

```swift
enum Kind: String, ExpressibleByArgument, EnumerableFlag {
case one, two
case three = "custom-three"
}

@Flag var allowedKinds: [Kind] = []
@Option() var kind: Kind
```

`case three = "custom-three"` from above is considered as `--three` for a flag
from `allowedKinds`, but as `custom-three` as an option value for `--kind`.

This is the case in the 1.7.0 & main completion scripts, in ToolInfoV0 & even in SAP's
command-line argument verification. It seems to me that it should be consistent
throughout; of the 2 options, `custom-three` seems more sensible.

**ArgumentParser version:** `main`
**Swift version:**
swift-driver version: 1.120.5 Apple Swift version 6.1 (swiftlang-6.1.0.110.21 clang-1700.0.13.3)
Target: arm64-apple-macosx15.0

### Checklist
- [x] If possible, I've reproduced the issue using the `main` branch of this package
- [x] I've searched for [existing GitHub issues](https://github.com/apple/swift-argument-parser/issues)

Contributor guide

Open the contributing guide

Research direction

Start with CompletionScriptTests.swift and trace how raw values are rendered for EnumerableFlag cases versus ExpressibleByArgument option values. Compare the corresponding ToolInfoV0 and command-line argument verification paths, then run the relevant tests. Done means the custom-three raw value is handled consistently across completion scripts and argument verification.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.