apple / apple/swift-argument-parser
@Flag properties that begin with "v" do not work.
- Dominant language
- Swift
- Stars
- 3.8k
- Forks
- 411
- Avg merge
- 7d 14h
- Merged PRs (30d)
- 15
Description
I had a "verbose" flag for log output, but it was getting completely ignored and failed silently.
**ArgumentParser version:** `1.0.2`
**Swift version:**
```
swift-driver version: 1.26.9 Apple Swift version 5.5.1 (swiftlang-1300.0.31.4 clang-1300.0.29.6)
Target: arm64-apple-macosx12.0
```
### Checklist
- [ ] 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)
### Steps to Reproduce
Create your own `ParsableCommand` with a flag such as:
```
struct MyCommand: ParsableCommand {
// other boilerplate here.
@Flag(name: .shortAndLong, help: "Whether to enable verbose logging.")
var verbose = false
mutating func run() throws {
print("Verbose Logging Enabled: \(self.verbose)") // is ALWAYS false.
// the rest of what you do here.
}
}
```
If you include this flag in your command line arguments, it is not parsed as expected.
### Expected behavior
The Flag should be set to true when you `swift run MyCommand --verbose`
Stretch goal: The compiler should fail or complain or warn about your variable name.
### Actual behavior
The argument --verbose is ignored and "fails silently"
### Workaround
make a custom flag name that doesn't begin with "v". In this case "fatlog" did the trick.
Contributor guide
Research direction
Start with the reported ParsableCommand example and its @Flag(name: .shortAndLong) property, then run it with --verbose to confirm the flag remains false. Trace how the flag is parsed and add a regression check showing that --verbose sets verbose to true; the issue is fixed when that behavior works without the workaround name.
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
- Clearly specified
- Newbie friendliness
- 45/100