-
Notifications
You must be signed in to change notification settings - Fork 344
Closed
Labels
good first issueGood for newcomersGood for newcomers
Description
Let's say, it's possible to configure a String
-typed option:
- with
help
text; - with
completion
; - with default value.
In fact, we can do either two of these, but combining three of these will cause compilation failure.
ArgumentParser version: 1.0.2
, main
Swift version: swift-driver version: 1.26.21 Apple Swift version 5.5.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30)
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
Minimal code to reproduce:
import ArgumentParser
struct Run: ParsableCommand {
@Option(help: "", completion: .file())
var string: String = ""
func run() {}
}
Similar bug with String?
:
@Option(completion: .file())
var string: String? = ""
Expected behavior
Compile successfully.
Actual behavior
main.swift:5:26: error: cannot convert value of type 'String' to expected argument type '[String]'
var string: String = ""
^
main.swift:5:9: error: property type 'String' does not match 'wrappedValue' type 'Array<String>'
var string: String = ""
^~~~~~
main.swift:5:9: note: cannot automatically synthesize 'Decodable' because '<<error type>>' does not conform to 'Decodable'
var string: String = ""
^
main.swift:3:8: error: type 'Run' does not conform to protocol 'Decodable'
struct Run: ParsableCommand {
^
Swift.Decodable:2:5: note: protocol requires initializer 'init(from:)' with type 'Decodable'
init(from decoder: Decoder) throws
^
Workaround
For anyone who encountered such error, you can workaround with a non-op transform
:
// ✅ It works!
@Option(help: "", completion: .file(), transform: {String($0)})
var string: String = ""
Metadata
Metadata
Assignees
Labels
good first issueGood for newcomersGood for newcomers