[swift-evolution] [Pitch][stdlib] Command Line Option Parsing & Help
felixcca at yahoo.ca
Thu Aug 18 00:54:58 CDT 2016
If we introduce a new API to parse command-line arguments now, we're committing to support it for a very long time. It seems to me that this is the kind of thing that could evolve with the language, so I'm not really in favor of fixing an implementation now.
Imagine this hypothetical scenario:
Swift 3 adds a program argument parser in the standard library;
Swift 4 implements an awesome feature that makes it possible to make a much better program argument parser;
Someone else implements that better argument parser that 99.9% of the Swift community prefers over the standard one;
We're stuck supporting the old and ugly parser as the standard library is part of the ABI, even though almost nobody uses it anymore.
To me, because of the not particularly low risk of deprecation, this should be left to third-party packages for now.
> Le 17 août 2016 à 01:20:05, Russ Bishop via swift-evolution <swift-evolution at swift.org> a écrit :
> 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
> swift-evolution mailing list
> swift-evolution at swift.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution