3 ms·
A better question is why OP isn't using a library that will do it for them! Python's argparse is pretty good in this respect. Even if you don't supply help tex
by tom_ 3y ago
A better question is why OP isn't using a library that will do it for them!
Python's argparse is pretty good in this respect. Even if you don't supply help text and good metavar names, it'll at least give you --help output showing which options are supported, and adding help text and helpful metavar names is not much additional effort.
argparse has inspired a number of knockoffs in other languages, and the ones I've used are pretty good at --help output too. (Or you can write your own! If you've done this not only long enough to not only forget the syntax of command line tools you've written, but also often enough to have recognised this as a repeated trend, the effort involved could be worth it.)