~/talk

Building Swift Command Line Tools

Talkat #Pragma Conference 2024 · 2024-10-29..10-30· [developer-experience, swift]
slides:none on file

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

  1. 0:00Introduction to Swift CLIs
  2. 1:49Why use Swift for scripting
  3. 2:32Basic input and output in Swift
  4. 3:56Handling command line arguments
  5. 4:40Reading user input and environment
  6. 5:44Writing to standard error and files
  7. 6:45Making scripts executable
  8. 7:25Creating Swift packages for CLIs
  9. 8:50Running CLIs in Xcode
  10. 9:53Leveraging Swift package dependencies
  11. 10:36Introducing Swift Argument Parser
  12. 12:19Defining commands and subcommands
  13. 13:23Handling arguments and options
  14. 14:49Custom types and validation
  15. 15:53Error handling and exit codes
  16. 17:17Adding help and documentation
  17. 18:19Unit testing Swift CLIs
  18. 19:02Styling output with ANSI codes
  19. 19:44Building GitHub Actions annotations
  20. 21:32Leveling up with additional tools
  21. 23:15Sharing logic between apps and CLIs
  22. 23:58Distributing your Swift CLI
  23. 24:39When to choose Swift over shell
  24. 25:21Q&A session
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.