Open ericcornelissen opened 1 year ago
You might be interested in these benchmarks.
There are also features you don't use now but might want to have in the future:
clap
and lexopt
and xflags
can handle it. You don't get it for free, you'd have to switch from String
to OsString
/PathBuf
, but it's useful for an rm
to be able to delete files with problematic names.argh
doesn't support the --interactive=once
and --preserve-root=all
syntax of GNU rm, and some of the other parsers might not either. (In clap
this is require_equals
, in getopts
this is optflagopt
, in lexopt
this is optional_value
.)Thanks for chiming in @blyxxyz, the benchmarks are very useful and so are the other suggestions. In fact, I created an issue to support invalid Unicode paths. I also added the considerations to the issue description as (for now) potential requirements.
Technical Change
Summary
This project currently uses the
clap
crate for CLI argument parsing. Clap is easy to work with, concise, and provides a lot out of the box. However, it is not small (see "Size Analysis" section for more details).As such, it might be worth investigating alternative argument parsing libraries for this project. After all, this project doesn't require anything special, just:
Requirements
--recursive
)-r
)-rf
)--interactive=WHEN
)--
)foo.bar
)OsString
(or similar) argumentsAlternatives
clap
without the derive feature[^1]Using the(unmaintained)docopt
crateUsing the(maintenance mode)structopt
crategetopt
crate (used byrustc
)lexopt
cratexflags
crateargh
crate[^1]: Based on https://github.com/rosetta-rs/argparse-rosetta-rs/tree/ec59407e70cb8993f9a81f8b2c3df1397fe84422#results derived code is less optimized for size.
Size Analysis
Using
cargo-bloat
we can find the functions of the executable that take up the most space. For example, of the 25 biggest functions, 15 areclap
-related:More stats
### `N=10` 4 of the 10 biggest function are related to `clap`: ```sh $ cargo bloat --release -n 10 Finished release [optimized] target(s) in 0.07s Analyzing target/release/rust-rm File .text Size Crate Name 3.3% 4.9% 31.1KiB std std::backtrace_rs::symbolize::gimli::resolve::{{closure}} 2.9% 4.3% 27.5KiB clap_builder clap_builder::parser::parser::Parser::get_matches_with 2.4% 3.5% 22.4KiB std addr2line::ResDwarf