[HN Gopher] Swift: Announcing ArgumentParser
       ___________________________________________________________________
        
       Swift: Announcing ArgumentParser
        
       Author : zdw
       Score  : 39 points
       Date   : 2020-02-28 20:47 UTC (2 hours ago)
        
 (HTM) web link (swift.org)
 (TXT) w3m dump (swift.org)
        
       | paulddraper wrote:
       | One of my very, very, very favorite things about Python is
       | argparse. [1]
       | 
       | Very few libraries creates its API so well as to transcend its
       | origins (JodaTime comes to mind).
       | 
       | * Node.js [2]
       | 
       | * Java/JVM [3]
       | 
       | * Go [4]
       | 
       | * Lua [5]
       | 
       | * C++ [6] [7]
       | 
       | It appears there is no Swift port.
       | 
       | That is unfortunate, because besides the basics (optionals,
       | positions, defaults, short and log options, auto generated docs,
       | subcommands, descriptions, repeating options), it lets you do
       | argument groups, mutually exclusive options, customizable help
       | behavior, variable customization, custom parsers/validators,
       | options with multiple arguments. There's even Python support for
       | shell autocomplete library. [7].
       | 
       | (One potential limitation is that it is naturally dynamic, and
       | not typesafe like Swift's new ArgumentParser. IMO that is of
       | relatively small practical importance compared to its other
       | features.)
       | 
       | It's both simple enough to get going, but sophisticated enough
       | that I've never wanted for anything. It's the first thing I look
       | for when writing a CLI.
       | 
       | [1] https://docs.python.org/3/library/argparse.html
       | 
       | [2] http://nodeca.github.io/argparse/
       | 
       | [3] https://argparse4j.github.io/
       | 
       | [4] https://github.com/akamensky/argparse
       | 
       | [5] https://github.com/mpeterv/argparse
       | 
       | [6] https://github.com/jbms/argparse
       | 
       | [7] https://github.com/mmahnic/argumentum
       | 
       | [8] https://pypi.org/project/argcomplete/
        
         | hobofan wrote:
         | > Very few libraries creates its API so well as to transcend
         | its origins
         | 
         | At least in the argument parsing space, docopt[0] did as well,
         | with official implementations in ~22 languages. It might not
         | always be the best native approach, but the one I will reach
         | for when I have to do argument parsing in a new language.
        
           | paulddraper wrote:
           | Docopt is indeed popular. By virtue of having it creating its
           | own language, its API is naturally "transcendent." :)
           | 
           | I've used it in Ruby, for which IMO it is the best available
           | choice.
           | 
           | But there is only so much you can express in docopt, and I
           | quickly begin missing the flexibility of a "real" API and
           | argparse.
        
       | alexashka wrote:
       | Can we please have a 'New Version', 'Old Version' comparison,
       | side by side.
       | 
       | If this is an improvement, why are you _telling_ me instead of
       | _showing_ me?
       | 
       | Personally, the problem is command line tools, not argument
       | parsing. Why would anyone create a command line tool instead of a
       | GUI that only lets you enter the correct set of arguments that go
       | together, grouped into a coherent UI?
       | 
       | The end result should be a json. We all know how to parse json in
       | Swift and every other language in existence.
        
         | Jtsummers wrote:
         | If you write your program well enough (which is not hard), GUI
         | or CLI doesn't matter, you've written a modular tool that can
         | be interfaced with any way you want. And sometimes CLI is a
         | better way to interface (CLIs can be chained together using
         | standard mechanisms much more easily than GUIs).
         | 
         | And why should everything be JSON? It's not the best format
         | ever for all the things (there isn't one).
        
       ___________________________________________________________________
       (page generated 2020-02-28 23:00 UTC)