Our great sponsors
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
-
docopt-ng
Humane command line arguments parser. Now with maintenance, typehints, and complete test coverage.
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
These days i use typer (https://typer.tiangolo.com/), but docopt remains a fan favorite of mine for being just so darn cute.
it's a shame that the last i checked, there wasn't really a formal grammar for it and so doing a lot of the modern conveniences i like is either hard or impossible, but the idea's still charming.
I like Docopt for quick scripts, used it both in Python and Rust projects. It is quite unflexible though.
The Rust Docopt implementation¹ was deprecated this year, which is probably good because clap v3 (https://github.com/clap-rs/clap) is so awesome. In a project of mine (tealdeer), I noticed that docopt.rs was responsible for the huge majority of CPU instructions when running the binary: https://github.com/dbrgn/tealdeer/issues/106#issuecomment-59... I then switched² to clap and shaved off almost a megabyte from the release binary³. Performance improved as well, time required for rendering a tldr page went down from ~15.9 ms to ~12.4 ms⁴. With the migration, we also managed to reduce a lot of custom validation logic and move this logic into the derive macro attributes.
¹ https://github.com/docopt/docopt.rs
I like Docopt for quick scripts, used it both in Python and Rust projects. It is quite unflexible though.
The Rust Docopt implementation¹ was deprecated this year, which is probably good because clap v3 (https://github.com/clap-rs/clap) is so awesome. In a project of mine (tealdeer), I noticed that docopt.rs was responsible for the huge majority of CPU instructions when running the binary: https://github.com/dbrgn/tealdeer/issues/106#issuecomment-59... I then switched² to clap and shaved off almost a megabyte from the release binary³. Performance improved as well, time required for rendering a tldr page went down from ~15.9 ms to ~12.4 ms⁴. With the migration, we also managed to reduce a lot of custom validation logic and move this logic into the derive macro attributes.
¹ https://github.com/docopt/docopt.rs
I like Docopt for quick scripts, used it both in Python and Rust projects. It is quite unflexible though.
The Rust Docopt implementation¹ was deprecated this year, which is probably good because clap v3 (https://github.com/clap-rs/clap) is so awesome. In a project of mine (tealdeer), I noticed that docopt.rs was responsible for the huge majority of CPU instructions when running the binary: https://github.com/dbrgn/tealdeer/issues/106#issuecomment-59... I then switched² to clap and shaved off almost a megabyte from the release binary³. Performance improved as well, time required for rendering a tldr page went down from ~15.9 ms to ~12.4 ms⁴. With the migration, we also managed to reduce a lot of custom validation logic and move this logic into the derive macro attributes.
¹ https://github.com/docopt/docopt.rs
If the PL you are using already has named parameters with defaults then you can roll a CLI on top of it with a better spcified "spec" language (the PL itself) and with less work. There are a few Python packages for this and https://github.com/c-blake/cligen
This is theoretically even possible for C++ with some kind of compile-time reflection API, but the way the C preprocessor works probably makes it hard to preserve structured comments for automatic documentation extraction. It was quite easy to do in Nim.
Just FYI, the docopt package isn't updated anymore and the maintainer doesn't answer any inquiries. There are some annoying bugs one runs into when using the official docopt package. So I recommend using docopt-ng instead: https://github.com/jazzband/docopt-ng