Building Swift Command Line Tools
summary
Shows how to move from shell scripts to real CLIs using Swift standard I/O, CommandLine.arguments, ProcessInfo and readLine, then package as an executable with either main.swift or an @main type. Uses Swift Argument Parser for subcommands, @Argument/@Option/@Flag, validate() and custom exit codes, supports async with AsyncParsableCommand, colors output with ANSI or colorizer, and emits GitHub Actions annotations. Example tool XCBeautify builds, tests, and compiles for macOS and Linux; distribute via GitHub Releases or Homebrew.
AI-written summary · about
chapters (24)
- 0:00Introduction to Swift CLIs
- 1:49Why use Swift for scripting
- 2:32Basic input and output in Swift
- 3:56Handling command line arguments
- 4:40Reading user input and environment
- 5:44Writing to standard error and files
- 6:45Making scripts executable
- 7:25Creating Swift packages for CLIs
- 8:50Running CLIs in Xcode
- 9:53Leveraging Swift package dependencies
- 10:36Introducing Swift Argument Parser
- 12:19Defining commands and subcommands
- 13:23Handling arguments and options
- 14:49Custom types and validation
- 15:53Error handling and exit codes
- 17:17Adding help and documentation
- 18:19Unit testing Swift CLIs
- 19:02Styling output with ANSI codes
- 19:44Building GitHub Actions annotations
- 21:32Leveling up with additional tools
- 23:15Sharing logic between apps and CLIs
- 23:58Distributing your Swift CLI
- 24:39When to choose Swift over shell
- 25:21Q&A session
related talks
24mSwift Scripts: Zero to Hero
38mBuilding CLI Tools in Swift
32mBuilding command-line user experiences with Swift
30mCLI Tools for All the Things
16mBuilding an interactive CLI app in Elixir
26mPractical Cross-Platform Swift
23mBuilding Bitrise Automations With Swift
44mSwift Packages - Dependency Management of the Future
