Using ArgumentParser with Swift 5.2
cwoloszynski77 opened this issue · 7 comments
When trying to use the new 'ArgumentParser' in a project with Swift5.2 on my machine (MacOSX Catalina, 10.15.5), I get an error when trying to run the following directly, but when I do a 'swift sh eject' and then build, it works.
#!/usr/bin/swift sh
import ArgumentParser // apple/swift-argument-parser
struct PostData: ParsableCommand {
@argument() var hostname: String
static func run() {
print("running")
}
}
PostData.run()
The error I get is:
'postData' /Users/charlie/Library/Developer/swift-sh.cache/cbf17a619a0a1e175271a55751e0aeb3: error: dependency 'ArgumentParser' in target 'postData' requires explicit declaration; reference the package in the target dependency with '.product(name: "ArgumentParser", package: "swift-argument-parser")'
Am I doing something wrong or is this an issue with Swift 5.2 or a change in SPM?
Looking at #115, it looks like this is the problem where the product name is different than the repository name.
Can I suggest that we allow the import line to include the product name alternative as an optional value in the comment section by adding in a set of parentheses? E.g. something like:
import ArgumentParser // apple/swift-argument-parser (ArgumentParser)
This could be a good solution and would fix #119 as well if we could specify (Path.swift)
FYI @cwoloszynski77 the issue with ArgumentParser
is fixed with swift-sh 1.18.0 as far as I know.
I was using 1.18.0 when I found this. I don’t think it is fixed yet, or I don’t understand what I needed to do to work around this issue.
I was using 1.18.0 when I found this. I don’t think it is fixed yet, or I don’t understand what I needed to do to work around this issue.
me too
@cwoloszynski @iT-Boyer the ArgumentParser
issue is fixed with the github 1.18.0. Unfortunately the changes from github never made it into the homebrew v1.18.0. See #118.
You can either install swift-sh using
brew reinstall --build-from-source mxcl/made/swift-sh
Or use mint to install it. You'll have to uninstall the homebrew version if you use mint
.