Swift CLI template based on Swift Package Manager, with a simple script to generate your CLI project.
- Clone this repo.
- Open terminal and
cd DOWNLOADED_REPO_PATH/SwiftCLITempalte. - Run
./generate-cli-project.shfor help.- Example: run
./generate-cli-project.sh MyCLIProject my-cli
- Example: run
cd MyCLIProjectand write your CLI logic.maketo build and run your CLI project.make testto run unit tests.
- Faster to write? ...not really faster than writing GUI in Delphi in 1998.
- Easier to use? ...not for young developers grew up with Xcode.
- Cross-platform? Yes, definitely easier to support multiple platforms than GUI.
- CI/CD? DevOps? ...yes, can be used anywhere. There may not be GUI, but there is always a shell environment.
- ...and it's actually faster to write and easier to use if you are used to it.
- Swift is a modem, type safe, protocol oriented language that promotes good architectural design and coding practice.
- First class citizen in macOS, decent support in Linux.
- Swift Argument Parser is a great library for CLI.
- In macOS, you can invoke Apple's A/V processing, Machine Learning frameworks, etc.
- ...as an iOS developer, you already unlocked "Lv1 swift" skill, so why not use it?
Or why not Xcode? First of all, even in 2023, SPM still feels worse than Cocoapods. But it's good enough for CLI usage.
So the main point is, Xcode feels too "heavy" for most CLI usage. And Xcode project files look ugly. Tools like tuist can help, but those are more things to learn.
Having these being said, Xcode allows you to debug in GUI if needed. If that's the case, use something else instead.
- Swift argument parser is a must-have for CLI as long as you need argument parsing, which is 99% the case.
- After using Quick and Nimble, you really can't go back to
XCTest. Who doesn't love pretty codes?
- Feel free to run
swift buildand so on, it's the same thing. Howevermakeis faster to type and already became my muscle memory. - You don't need to learn the whole
makesystem to use it. Likevim, even knowing 5% ofmakewill save you a lot of time in CLI world.
This is why I make this project open source! Feel free to make your own changes.
Here are some to-do items from myself:
- Replace the generator script with a Swift CLI utility.
- Setup dependency via CLI argument.
- Setup Swift version via CLI argument.