Tuesday, January 22, 2019

Kick-ass CLI Tools In Swift

Daniel Duan:

Programmers whine about ergonomics partially because we are previlidged and spoiled. But mostly because our attention is a limited resources. Mixing API conventions distracts us from solving the problem at hand. Bad ergonomics, therefore, drives away a good potion of users who cares about quality of their tools.


File system APIs being in Foundation as opposed to the standard library is probably a temporary condition. Nevertheless, it has at least the following implications[…]


The next killer CLI tool is still more likely to be written in Go or Rust, than in Swift. Hopefully, somewhere in these speculations is a true cause of this phenomena. Maybe someone reading this will be inspired to accelerate change that will eventually revert the condition.

Still, Swift+Foundation works pretty well for writing simple CLI tools to aid in my Mac development and maintenance. And swift-sh (via Mattt Thompson) looks like it will help.

Previously: @dynamicCallable: Unix Tools as Swift Functions.

Update (2019-01-24): Florent Pillet:

So Vapor has another hidden gem: a pretty cool framework to build CLI apps, so I can reuse Vapor add-ons from the ecosystem to write my own local tools.

No terribly well documented, but worth a look.

2 Comments RSS · Twitter

"Still, Swift+Foundation works pretty well for writing simple CLI tools"

Just out of curiosity, how do you handle/parse command options (short and long) in your Swift command line tools?

I always found the suggested solutions to be painful and incompatible across the Swift versions I tried.

Also the size of the command line tools built with Swift was an issue (compared to C/Obj-C versions).

@Stephane I think you’re right that there isn’t a good way to do that, but my tools are simple enough that I don’t need an argument parsing library, and the binary size isn’t an issue because (for convenience) just run the text directly like a script.

Leave a Comment