I'm writing a CLI tool in Swift 4 for MacOS. If I "cheat" and use a shell function, then the curl command, I get exactly the result I'm after:
func shell(_ args: String...) -> Int32 {
let task = Process()
task.launchPath = "/usr/bin/env"
task.arguments = args
task.launch()
task.waitUntilExit()
return task.terminationStatus
}
shell("/usr/bin/curl", "-OL", "http://mywebserver/myfile.whatever")
How do I do the same thing natively in Swift 4? I tried using the just library: https://github.com/dduan/Just but I can't figure out how to simply get it to download a file from a URL to a specific location on the file system. I've also found various solutions for Swift 3 and 5, and iOS which obviously don't work for me.