Crates.io | onlyargs |
lib.rs | onlyargs |
version | 0.2.0 |
source | src |
created_at | 2023-04-10 23:56:31.144498 |
updated_at | 2024-02-22 17:04:55.323414 |
description | Obsessively tiny argument parsing |
homepage | |
repository | https://github.com/parasyte/onlyargs |
max_upload_size | |
id | 835577 |
size | 18,720 |
Only argument parsing! Nothing more.
#[derive(OnlyArgs)]
on a struct and parse CLI arguments from the environment into it with minimal boilerplate.The Minimum Supported Rust Version for onlyargs
will always be made available in the MSRV.md file on GitHub.
There's an argument parsing crate for everyone. So why write another?
onlyargs
is an example of extreme minimalism! The only thing it provides is a trait and some utility functions; you're expected to do the actual work to implement it for your CLI argument struct. But don't let that scare you away! The parser implementation in the "full" example is only around 50 lines! (Most of the file is boilerplate.)
The goals of this parser are correctness, fast compile times, and convenience.
No shenanigans! The only unsafe
code is abstracted away in the standard library.
OsString
so that invalid UTF-8 can be accepted as an argument.OsString
or converted to a PathBuf
with no extra cost. Easily access your mojibake file systems!OsString
are handled by your parser implementation. It's only as correct as you want it to be!Argument parsing is dead simple (assuming your preferred DSL is opinionated and no-nonsense). There is no reason to overcomplicate it by supporting multiple forms like --argument 123
and --argument=123
or -a 123
and -a123
. Just pick one!
The provided examples use the former in both cases: --argument 123
and -a 123
are accepted for arguments with a value. Supporting both long and short argument names is just a pattern!
Some("--argument") | Some("-a")
It is fairly straightforward to derive an implementation with a proc_macro. Compare the "full-derive" example to the "full" example.