5 ms·
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 ab
by ben0x539 1y ago
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)
- ameliaquining 1y agoI 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.
- iloveyoudearly 1y agoNot 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 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.
- porridgeraisin 1y agoNice. 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/313a26ee3b827f7338df78c72ccbb247 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.
- never_inline 1y agoPeople 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.
- woile 1y agoIn Python you can use pydantic to create a cli: https://docs.pydantic.dev/latest/concepts/pydantic_settings/#command-line-support https://docs.pydantic.dev/latest/concepts/pydantic_settings/...
- wonger_ 1y agoDocopt is great! http://docopt.org/ http://docopt.org/ There's implementations for other languages, too. TIL about structopt, thanks.