Module exposing Unix command line tools as Swift 5 @dynamicCallable functions
A few words of warning: This is intended as a demo. It should work just fine, but in the name of error handling and proper Swift beauty, you might want to approach forking processes differently 🤓 (BTW: PRs are welcome!)
Part of this blog post: @dynamicCallable: Unix Tools as Swift Functions.
The regular Swift Package Manager setup process:
mkdir ShellConsumerTest && cd ShellConsumerTest swift package init --type executable
import Shell print(shell.host("zeezide.de"))
// swift-tools-version:5.0 import PackageDescription let package = Package( name: "ShellConsumerTest", dependencies: [ .package(url: "https://github.com/AlwaysRightInstitute/Shell.git", from: "0.1.0"), ], targets: [ .target(name: "ShellConsumerTest", dependencies: [ "Shell" ]), ] )
Remember to add the dependency in two places. WET is best!
swift testpatch the
/usr/bin. You may want to run the binary directly to make lookup work properly.
Install a Swift 5 Snapshot
For this to work, you need to have Swift 5 installed. As of today Swift 5 hasn't been released yet, but Apple is providing prebuilt Swift 5 development toolchains over at: swift.org. Just install the toolchain, and select it in the Xcode "Toolchains" menu.
If you are living on the commandline, make sure to call
export TOOLCHAINS=swift to get access to the selected version.