GitHub lists 1,524 Swift packages tagged ‘cli’.
Search ‘readLine’ in their code. It’s everywhere.
interactive CLI prompts in Swift? That’s the unicorn everyone’s chased but nobody caught—until Promptberry.
This library doesn’t just patch holes. It bulldozes Swift’s stdlib for leaving developers in the dark ages of input. Print. ReadLine. Repeat. Yawn.
Swift CLI Input: A Caveman’s Toolkit
Look. You’re building a package manager or scaffold tool. User hits Enter on empty name? Too bad. No validation. No pretty error. Just crash or soldier on with garbage.
And choices? Forget lists. No arrows, no autocomplete. Ctrl+C? Hope your do/catch saves the day, or it’s segfault city.
Swift’s great for servers, apps. But CLI? It’s like giving a chef a butter knife.
Promptberry laughs at that. Text inputs with placeholders. Inline validation that doesn’t nuke your typing. Password masks. Selects you navigate like a pro.
Here’s the proof, straight from their docs:
let name = try Promptberry.text( “Project name?”, placeholder: “MyApp”, validate: { $0.isEmpty ? “Name cannot be empty.” : nil } )
Validation hits instantly. User sees the error right below, keeps typing. Magic? Nah. Just what 2010 called ‘civilized’.
But wait—Swift’s been around since 2014. Node.js had Inquirer.js by 2012. Python’s Click and Rich? Ancient history.
My hot take: Apple’s too busy polishing UIKit to notice CLI devs are starving. Promptberry’s the indie hero forcing their hand. Bold prediction—this ends up in Swift ArgumentParser 2.0, whether they admit it or not.
Can Promptberry Handle Real Choices?
Single pick? Select renders a list. J/K or arrows. Enter seals it.
let projectType = try Promptberry.select( “Project type:”, options: [“Executable”, “Library”, “Plugin”] )
Longer lists? Autocomplete filters on the fly. Type ‘mit’, boom—MIT license pops.
Multiples? Multiselect. Space to toggle, Enter to go. Pre-select defaults if you’re nice.
AllowOther: true lets rebels type custom crap. Smart.
It’s not hype. This is what users expect from npm init or pip installers. Swift’s catching up—finally.
Password fields mask with dots or stars. Multiline for descriptions—Ctrl+D to submit, Enter for new lines. Confirm before nuking dirs, with custom Yes/No text.
Guard confirmed else { bail }. Clean.
And async? Tasks with spinners. One fails, stops, shows error. Progress bars for file copies—total count, advance per step, complete message.
try await tasks([ PromptTask(“Scaffolding project structure”) { try await scaffold() }, PromptTask(“Writing Package.swift”) { try await writeManifest() }, PromptTask(“Installing dependencies”) { try await installDeps() }, ])
Ctrl+C throws PromptCancelled everywhere. Catch it, outro nicely. Intro/outro bookends the session—feels polished, not hacky.
Why Does This Matter for Swift Devs?
You’re skeptical. ‘Another lib? Swift Package Manager handles deps fine.’ Sure. But without this, your tool’s a questionnaire from 1995.
Corporate spin? None here—it’s open source, no Apple strings. But here’s the rub: Swift’s CLI ecosystem lags because basics like this were missing.
Promptberry isn’t perfect. No fuzzy search yet? Docs could demo error styles more. But it ships. Works on macOS, Linux—iOS? Who cares for CLI.
Install: .package(url: “https://github.com/binaryship/promptberry”, from: “0.1.0”) or whatever latest is.
Test it. Scaffold a project. Feel the difference.
Historical parallel: Remember Bash completion wars? This is Swift’s readline rebellion. It’ll standardize interactive flows, make tools stickier.
Prediction: In two years, every Swift CLI copies this API. Fork it, improve it—community wins.
One gripe—why no colors out of box? Pair with Swiftline or Rainbow. But that’s nitpick. Core’s solid.
Wrap prompts in do/catch. Always.
Promptberry.intro(“New Swift Project”)
// your magic
Promptberry.outro(“Happy coding!”)
Done. Professional.
🧬 Related Insights
- Read more: Cloudflare’s EmDash: The AI-Native WordPress Reboot That Could Reshape the Web
- Read more: Duolingo’s Kubernetes Leap: Ditching ECS for a Scalable Future
Frequently Asked Questions
How do I add Promptberry to my Swift CLI tool?
In Package.swift: .package(url: “https://github.com/binaryship/promptberry”, from: “1.0.0”). Import Promptberry. Boom—prompts ready.
What’s the difference between Promptberry text and select?
Text for free input, validates inline. Select for lists—arrows or type to pick one. Use select when options are fixed; text otherwise.
Does Promptberry work with async Swift code?
Yes. Tasks for spinners, progress for counts. Await them. Catches cancels gracefully.