Top
Best
New

Posted by rajman187 7/1/2025

Rust CLI with Clap(tucson-josh.com)
97 points | 88 commentspage 2
mootoday 7/1/2025|
That was a great intro to clap, thanks for writing it up!

I've been building clap CLIs for a while and started to put together a template: https://github.com/mootoday/cli-template.

It also includes a crate I developed to reduce the boilerplate code for nested commands: https://crates.io/crates/clap-nested-commands

tucson-josh 7/1/2025|
Thanks for the feedback. Nested commands are definitely full of boilerplate and your crate looks interesting.
FujiApple 7/1/2025||
Something I’ve been working on recently is a command line tool [1] to bring clap declarative command line parsing to shell scripts. Unfinished WIP but largely functional.

[1] https://github.com/fujiapple852/claptrap

gametorch 7/1/2025||
The compile time guarantees + declarative nature make Clap so amazing and foolproof. This is like heaven compared to imperative, arcane incantations like getopt.
tempodox 7/1/2025||
Clap is the way to go. It makes command line argument parsing a breeze.
b0a04gl 7/1/2025|
10kloc for command line parsing. TEN THOUSAND LINES. pico-args does it in 700 lines and probably handles 99% of real world use cases. compile times go to shit binary size bloats and for some edge case you'll never hit.most CLI tools need what three four flags max, maybe a subcommand or two. you don't need the swiss army knife of argument parsing for that. tried replacing clap with pico-args on three different projects last month. 80% reduction in compile time every single time. binary went from 8mb to 2mb on one of them.the "disk space is cheap" argument's acceptable partially but compile time isn't. developer experience isn't. startup time isn't. memory usage isn't
ModernMech 7/1/2025||

  No help generation
  Only flags, options, free arguments and subcommands are supported
  A properer parser would knew that --arg2 is a key and will return an error, since the value is missing.
  If such behavior is unacceptable to your application, then you have to use a more high-level arguments parsing library.
Yeah, no thank you. If we're talking about 700 LOC, I'm just going to write it myself rather than take on a dependency that won't even describe itself as a proper enough parser. This argument parser doesn't even handle the tedium of generating a help message for the user, and doesn't really parse the arguments -- what's the purpose of using it to do the argument parsing then?

So 700 LOC gets us a mediocre argument parser with no features. What do you get for an additional 9300 LOC? A "properer" parser (dev and user experience+). Help generation (dev experience+). Multiple interfaces (dev experience+). Color terminal output (user experience+). Suggested completions (user experience+).

Is it worth it? I dunno that's a per-project choice. If you absolutely need the smallest footprint and compile times possible, probably you don't want to go with clap. You also probably don't want to go with Rust.

MrJohz 7/1/2025||
Honestly, if you're doing something so small, even pico-args is a lot more than you need. Just use lexopt, and you get a very simple match-based DSL for defining your arguments, that even neatly sidesteps the limitations provided in pico.