3 ms·
If you write these sorts of things in Python, argparse is worth investigating: https://docs.python.org/3/library/argparse.html https://docs.python.org/3/library
by tom_ 1y ago
If you write these sorts of things in Python, argparse is worth investigating: https://docs.python.org/3/library/argparse.html 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!
- latexr 1y agoI 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/ruby/optparse ² https://github.com/apple/swift-argument-parser https://github.com/apple/swift-argument-parser
- yellowapple 1y agoMany 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 https://github.com/YellowApple/bales
- tom_ 1y agoRegarding other ports, I've also been pretty happy with https://github.com/nodeca/argparse 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 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.