Update to O'Reilly's Command-Line Rust book

72 points hunkamunka

My name is Ken Youens-Clark, and I'm the author of the book, Command-Line Rust (O'Reilly). I wanted to share that I've worked hard since the original 2022 publication to update the book with a new 2024 edition. All channels for the book such as Amazon, ebooks.com, and learning.oreilly.com carry the new version (look for the "2024 Updated Edition" banner).

Here's what has changed:

  • I've updated the clap (command-line argument parser) crate from v2.33 (which was the most recent version while I was writing in 2021) to v4. All my example programs illustrate both the builder and derive patterns. The GitHub "main" branch of https://github.com/kyclark/command-line-rust contains the derive patterns, and a separate "clap\_v4\_builder" shows the builder pattern. 
  • I simplified the programs to make them easier to teach. For instance, my first versions placed all the program logic into a library crate (src/lib.rs) that was called by src/main.rs. The new versions keep all source code in src/main.rs given that this book is focused on making binaries and not libraries.
  • I improved test output by using pretty\_assertions::assert\_eq for much better string comparisons. 
  • All programs use the anyhow crate for all Result values and returning errors from functions with bail! and anyhow!, making the code cleaner and easier to read.