Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

structopt/Clap's derive magic is one of the first things I miss when I go to write some more-or-less trivial program in a non-Rust language these days. Being able to define all the data for a command line argument in one place (how/where to store it, what the type/valid input is, the association between the name and a variable/field, the documentation for --help...) seems like table stakes but afaict almost every other argument parsing library makes me repeat myself to the point where it takes all the joy out of writing a simple program.

(Python's docopt is also amazing, fwiw)



I want to like docopt, but that the only data types it supports are boolean and string—if you want anything else, you have to do another round of parsing and error checking—destroys a lot of the advantage of using a high-level library for handling command-line arguments.


Not sure if it's on par with Clap, but for Python I don't see enough people talk about SimpleParsing: https://github.com/lebrice/SimpleParsing

It has quirks once you try to do something more complex/advanced, but for most of the simple stuff it's very nice to use.


People are used to the `click` way, where you can define args as function parameters. It's little more verbose but it helps click is a very established library which also provides many other things needed by CLI tools.

There's also `typer` from the creator of `fastapi` which relies on type annotations. I have not had the opportunity to use it.


In Python you can use pydantic to create a cli:

https://docs.pydantic.dev/latest/concepts/pydantic_settings/...


Nice. I had made something similar (but less featureful), funnily enough also for an ML training script usecase. Here it is in a gist:

https://gist.github.com/porridgewithraisins/313a26ee3b827f73...

I love the ergonomics of this method, and I was going to improve it to support subcommands, etc, but now I think I will use the library you posted.


Docopt is great! http://docopt.org/

There's implementations for other languages, too.

TIL about structopt, thanks.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: