News for hackers. Stuff that matters.
Re:Scripts I wrote that I use all the time by tom_ on Thursday October 23, 2025 @08:14AM (#45680957)
If you write these sorts of things in Python, argparse is worth investigating: https://docs.python.org/3/library/argparse.html - it's pretty easy to use, makes it easy to separate the command line handling from the rest of the code, and, importantly, will generate a --help page for you. And if you want something it can't do, you can still always write the code yourself!
Re:Scripts I wrote that I use all the time by latexr on Thursday October 23, 2025 @08:55AM (#45681251)
I don’t like Python in general, but even so I’ll say that argparse is indeed very nice. When I was writing ruby, I always felt that OptionParser¹ wasn’t as good. Swift has Argument Parser², officially from Apple, which is quite featureful. For shell, I have a a couple of bespoke patterns I have been reusing in every script for many years.

¹ https://github.com/ruby/optparse

² https://github.com/apple/swift-argument-parser

Re:Scripts I wrote that I use all the time by yellowapple on Friday October 24, 2025 @03:06PM (#45698043)
Many years ago I wrote a library I called “Ruby on Bales”¹ specifically due to my frustrations with the state of command-line argument parsing for Ruby scripts. I haven't touched it in a long while; maybe I should revisit it.

----

¹ https://github.com/YellowApple/bales

Re:Scripts I wrote that I use all the time by tom_ on Friday October 24, 2025 @05:46PM (#45699429)
Regarding other ports, I've also been pretty happy with https://github.com/nodeca/argparse, which works nicely from Typescript. Looks like it hasn't been updated for a while, but it's not like there's a great deal wrong with it.

https://github.com/p-ranav/argparse is a single-file argparse for Modern C++, which means it's typically straightforward, if baffling in places and a bit annoying to step through in the debugger.

The nice thing about the argparse ports is that provided they take their job seriously, your programs will all end up with a vaguely consistent command line UX in terms of longopt syntax, and, importantly, a --help page.