What does HackerNews think of docopt.rs?

Docopt for Rust (command line argument parser).

Language: Rust

I love docopt and I love rust. This thing written at [the docopt rust repo.] worries me

> 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

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² 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...

For small utilities I prefer to use docopt (https://github.com/docopt/docopt.rs). With docopt you just write down the documentation how you imagine the tool to be used and the docopt magic generates the command line parsing for you.
> Perhaps not quite as safe, but at least that they deliver the important parts of that safety without the cost of the learning curve.

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.

> A good (trivial) example was a great command parsing library just doesn’t exist yet.

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

[1] - https://github.com/docopt/docopt.rs

Yes, compiler plugins. For a relevant example, check out the Rust docopt crate[1].

An identical technique could be used for yacc or protobufs.

[1]: https://github.com/docopt/docopt.rs