What does HackerNews think of docopt.rs?
Docopt for Rust (command line argument parser).
> the wider docopt project is mostly unmaintained at this point. Consider using clap or possibly structopt instead.
It's a lovely way to internalize the CLI argument cultural norms, decrease confusing and verbose argument parsing, make argument parsing work-free for the developer, and make argument parsing a copy-paste across languages. There's no greater pleasure than iteratively adding options to your program by just adding a line of text
-n, --new-option Do something new
I honestly think making a docopt parser is just very hard, which may limit its future prospects.
[the docopt rust repo.]: https://github.com/docopt/docopt.rs
The Rust Docopt implementation¹ was deprecated this year, which is probably good because clap v3² 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
² https://github.com/clap-rs/clap
³ https://github.com/dbrgn/tealdeer/pull/108
⁴ https://github.com/dbrgn/tealdeer/pull/108#issuecomment-9448...
⁵ https://github.com/dbrgn/tealdeer/pull/108#issuecomment-9448...
Sorry to say this but a lot of unsafe code has been written in Java or C#, putting aside the NPEs and such. In Rust safety isn't only about eliminating SEGFAULTs and buffer overflows, but also preventing data races and most concurrency issues. It's common to add threading to cpu-bound code, without worrying about deadlocks or race conditions.
Rust also allows some very high-level code. Some of my favorite options out there:
- option (std): https://doc.rust-lang.org/std/option/index.html
- serde: https://github.com/serde-rs/serde
- docopt: https://github.com/docopt/docopt.rs
Some more features: generics (traits!), immutability by default, type inference, first-class functions, operator overloading, conversion between related types.
Arg parsing: https://github.com/docopt/docopt.rs
There is a Docopt implementation in Rust[1], which is used by Cargo. It tracks master and is regularly updated.
Interestingly, I've found people either love or hate Docopt, so maybe you knew about it but don't like it. :P
/shameless plug
An identical technique could be used for yacc or protobufs.