[WIP]: A (rearchitected) Swift port of https://github.com/sindresorhus/fast-cli in Swift, no third party frameworks. No disrespect to the original author intended, this is purely academic work
Currently main.swift is very "App like" which is fine - you look at the FastCLIDelegate class, look at the functions what it executes, and so on. However in most "scripting" languages - writing something like this is far simpler - you mostly read the script up to down and figure out what it does - it's a script, not an application (the distinction is important!).
Currently, the way the Swift interpreter appears to work is that it simply stops execution when it reaches the end of our Swift file - which is not great for something that needs to wait for WebKit to do its thing.
I had a stab at this problem early in the development of this program - why not use a DispatchSemaphore and go from there? Uhh, turns out that blocks the main runloop, and that's where the code is running so it never finishes 😬.
Sooo....what do we do here? I'm open to suggestions.
@davedelong had an excellent solution involving making a CLIMain() that has all the scaffolding that lets us write simple scripts.
Currently main.swift is very "App like" which is fine - you look at the
FastCLIDelegate
class, look at the functions what it executes, and so on. However in most "scripting" languages - writing something like this is far simpler - you mostly read the script up to down and figure out what it does - it's a script, not an application (the distinction is important!).Currently, the way the Swift interpreter appears to work is that it simply stops execution when it reaches the end of our Swift file - which is not great for something that needs to wait for WebKit to do its thing.
I had a stab at this problem early in the development of this program - why not use a
DispatchSemaphore
and go from there? Uhh, turns out that blocks the main runloop, and that's where the code is running so it never finishes 😬.Sooo....what do we do here? I'm open to suggestions.
CLIMain()
that has all the scaffolding that lets us write simple scripts.Other solutions welcome!