[swift-evolution] [Pitch][stdlib] Command Line Option Parsing & Help

Russ Bishop xenadu at gmail.com
Wed Aug 17 03:20:05 CDT 2016

I want to pitch a command line parsing addition to the standard library and get feedback before I polish up a full proposal.

Swift is being positioned to fill numerous functions, including as a local scripting language. I think that’s great but having tried to use it for that purpose there are a number of holes that need to be filled. Parsing command arguments (and printing help / doing shell autocompletion) is enough of a common task that I think it deserves to be part of the standard library… not to mention the huge PITA that it becomes to attempt to use a third-party library from a shell script.

I’m especially interested in Dimitri or Robert’s opinions on whether this kind of thing meets the standard library bar.

I’m looking toward some protocols that describe commands and their options, including short and long form (-/--), --opt=value, etc. Type-safe using enums that can convert from raw values, automatic printing of error & usage info when invalid options are passed. I’d also like to support loading localized descriptions for the help text from a bundle for i8n support (subject to what support exists in Swift’s Foundation).

If we can fill some of these holes it would make using swift scripts and command line utilities a much nicer experience.


Eventually I’d like to build up several components:

* Arguments - parse command line args, print command help, support shell auto-complete
* Terminal - Psuedo-terminal support, line discipline control, ANSI colors & other escape codes/commands, progress bars and other nice things for output
* TerminalEditor - a swift interface to ncurses, term box, or some similar cross-platform lib for doing command-line editing

More information about the swift-evolution mailing list