Live data from Hacker News

Swift: Announcing ArgumentParser

swift.org

1–10 of 27 posts

Re: Swift: Announcing ArgumentParser

#2
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/

Re: Swift: Announcing ArgumentParser

#3

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, r…

> 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.

Re: Swift: Announcing ArgumentParser

#4
post #3

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, r…

> 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.

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.

Re: Swift: Announcing ArgumentParser

#5
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.

Re: Swift: Announcing ArgumentParser

#6

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 k…

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).

Re: Swift: Announcing ArgumentParser

#7
Error: The value 'ZZZ' is invalid for ''

That is an awful default error for validating the type. The program knows it failed to parse as an Int but doesn't tell you anything about that.

Error: The value 'ZZZ' is invalid for '' of type Int

Also, the help should automatically tell you the expected types as well.

ARGUMENTS: : Int The highest value to pick.

Re: Swift: Announcing ArgumentParser

#8

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 k…

Personally, I prefer command-line tools over GUIs in many cases. Also, JSON doesn't help me at all if I'm working with other userland tools that expect something else. Piping is very important for CLI tools, so you have to talk the same language as the rest of the userland population.

Re: Swift: Announcing ArgumentParser

#9
post #7

Error: The value 'ZZZ' is invalid for ' ' That is an awful default error for validating the type. The program knows it failed to parse as an Int but doesn't tell you anything about that. Error: The value 'ZZZ' is invalid for ' ' of type Int Also, the help should automatically tell you the expected types as well. ARGUMENTS: : Int The highest value to pick.

There's an issue open for this, so they'll probably have it pretty soon: https://github.com/apple/swift-argument-parser/issues/8

Re: Swift: Announcing ArgumentParser

#10

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, r…

Java has picocli https://picocli.info/ which is superb.
Post reply on HN