Live data from Hacker News

Swift: Announcing ArgumentParser

swift.org

21–27 of 27 posts

Re: Swift: Announcing ArgumentParser

#21

Earlier quoted context omitted.

I can't stand argparse. It's like they tried their hardest to force you to be imperative and prevent composability. For example, instead of being able to define a parser for a subcommand and build a top-lever parser from that, you need to do this: parser = argparse.ArgumentParser() subparsers = parser.add_subparsers() a = subparsers.add_parser('a') a.add_argument('bar') A better API would look more like this: Parser(…

Python is indeed an imperative language, along with the others I listed. (Your proposal would indeed be at home in a functional language like LISP.) But I reject the idea that imperative is bad. You can compose imperative programming fine. def my_parser(parser): parser.add_argument('bar') parser = argparse.ArgumentParser() subparsers = parser.add_subparsers() my_parser(subparsers.add_parser('a')) my_parser(subparsers…

> Python is indeed an imperative language, along with the others I listed.

JavaScript has functional origins, and in practice quite a bit of JavaScript is written in a functional-lite style. As a JS developer, I find it quite infuriating that Python doesn't support these patterns, as they make code a lot more readable, and it seems to be a matter of principle rather than a technical limitation.

Re: Swift: Announcing ArgumentParser

#22
I'm somewhat clueless on this front. How usable is Swift outside of Apple OSes? I recall reading here that the language toolchain is broken all the time for other platforms. Is that still the case?

Re: Swift: Announcing ArgumentParser

#23

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…

C# has

System.CommandLine https://github.com/dotnet/command-line-api

CommandLineParser https://github.com/commandlineparser/commandline

NDesk.Options https://github.com/Latency/NDesk.Options

Mono.Options https://github.com/mono/mono/tree/master/mcs/class/Mono.Opti...

Re: Swift: Announcing ArgumentParser

#24
Cool! I've recently started writing many of my shell scripts in swift [shameless plug], but nice command line argument processing was something I wasn't looking forward to tackling. Now it looks like I won't have to :)

[shameless plug]: https://github.com/cobbal/swsh

Description:

A shell-scripting library for Swift, inspired by scsh.

swsh makes writing shell scripts more fun by exchanging bash (or similar) for a better thought-out language like Swift. In the process, a small amount of conciseness is traded for better quoting, error handling, and access to libraries.

Re: Swift: Announcing ArgumentParser

#25

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…

CLI tools exist for composibility. How many lines non-ignored lines are in my git worktree? git ls-files -coz --exclude-standard | xargs -0 cat 2>/dev/null -- | wc -l -- How would you ever create a GUI with that much flexibility?

Any ETL tool can do tasks like this. It probably has a terrible user interface, but they're enterprise tools and enterprise tools tend to be terrible, regardless of the style or task.

You're right that most GUIs don't tend to be composable -- but that's a function of how they're written, not an inherent limitation of GUIs. There's nothing fundamental about the VT100-style interface that makes it optimal for composition. And GUIs potentially offer some huge benefits, like not having to guess at what's flowing through the pipelines, or having a less painful way to deal with quoting/escaping, or offering an alternative to cryptic flags for configuring operations.

Screen editors used to get the same scorn. You probably haven't heard the term "screen editor" in a few decades because every editor today is a screen editor. Once they acquired most of the flexibility of line editors, it turned out that nobody actually preferred line editors.

People want composability, and you can do that in a screen editor better than a line editor -- and a GUI better than a terminal. You just have to have designers who care about it.

Re: Swift: Announcing ArgumentParser

#26

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…

CLI tools exist for composibility. How many lines non-ignored lines are in my git worktree? git ls-files -coz --exclude-standard | xargs -0 cat 2>/dev/null -- | wc -l -- How would you ever create a GUI with that much flexibility?

How would I add functionality to add a button that runs that exact command you just typed?

By adding an 'add button' with a text field where you type your bash script.

All I have to do to make a GUI superior to your terminal is to add some GUI to an existing terminal that people find useful...

Re: Swift: Announcing ArgumentParser

#27

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…

I can't stand argparse. It's like they tried their hardest to force you to be imperative and prevent composability. For example, instead of being able to define a parser for a subcommand and build a top-lever parser from that, you need to do this: parser = argparse.ArgumentParser() subparsers = parser.add_subparsers() a = subparsers.add_parser('a') a.add_argument('bar') A better API would look more like this: Parser(…

You should check out click : https://click.palletsprojects.com/en/7.x/

It is very powerful, uses special files stdin/stdout when file argument is "-", supports groups, subcommands...

Post reply on HN