[pmg-devel] [PATCH log-tracker] use pico-args instead of clap

Thomas Lamprecht t.lamprecht at proxmox.com
Wed Oct 25 10:50:28 CEST 2023


Am 24/10/2023 um 14:55 schrieb Dominik Csapak:
> Instead of upgrading from clap3 to clap4 (which seems to change their
> interface every year or so), switch to the much smaller pico-args.

Thanks for this conversion, while clap provides nice result, the churn
and complexity it brings along is currently simply not worth it IMO.

> 
> It has almost all features we need (except producing help output), but

And most important: works with OsString, i.e., the one must-have most
of those CLI argument crates are lacking..

> wihout any dependencies. This increases compile time and reduces the

s/increases/decreases/ I hope ;-)

> size of the resulting binary. It also reduces the lines of code.
> 
> The only difference is now the different output for errors, e.g. for
> missing values of options.
> 
> Help output is copied from the old clap output.

IMO it could be good to reference that this was done for termproxy too
(someone stumbling over this, could find reading the change, or just
background of other conversions helpful, while the chances are low here,
it's just too cheap to not mention that reference here – iow. yes I
had to spent too much time chasing some little crumbs of information
in commit (messages) that I really want any slightly relevant connection
written out explicitly)

https://git.proxmox.com/?p=pve-xtermjs.git;a=commitdiff;h=24d707d0506b120a085b06b5f2b6000696879a1e;hp=749ebb0907293a9f1cf0f5074e0a240f39f94f6f


> diff --git a/Cargo.toml b/Cargo.toml
> index 725976f..82a9a4f 100644
> --- a/Cargo.toml
> +++ b/Cargo.toml
> @@ -11,7 +11,7 @@ exclude = [ "build", "debian" ]

> +fn print_usage() {
> +    println!(
> +        "\
> +pmg-log-tracker {}
> +Proxmox Mailgateway Log Tracker. Tool to scan mail logs.
> +
> +USAGE:
> +    pmg-log-tracker [OPTIONS]
> +
> +OPTIONS:
> +    -e, --endtime <TIME>            End time (YYYY-MM-DD HH:MM:SS) or seconds since epoch
> +    -f, --from <SENDER>             Mails from SENDER
> +    -g, --exclude-greylist          Exclude greylist entries
> +    -h, --host <HOST>               Hostname or Server IP
> +        --help                      Print help information
> +    -i, --inputfile <INPUTFILE>     Input file to use instead of /var/log/syslog, or '-' for stdin
> +    -l, --limit <MAX>               Print MAX entries [default: 0]
> +    -m, --message-id <MSGID>        Message ID (exact match)
> +    -n, --exclude-ndr               Exclude NDR entries
> +    -q, --queue-id <QID>            Queue ID (exact match), can be specified multiple times
> +    -s, --starttime <TIME>          Start time (YYYY-MM-DD HH:MM:SS) or seconds since epoch
> +    -t, --to <RECIPIENT>            Mails to RECIPIENT
> +    -v, --verbose                   Verbose output, can be specified multiple times
> +    -V, --version                   Print version information
> +    -x, --search-string <STRING>    Search for string",
> +        env!("CARGO_PKG_VERSION")

nit: I find that a bit hard to read and think that this is one of the rarer
case where a "useless" intermediate variable could be indeed a bit useful.

let pkg_version = env!("CARGO_PKG_VERSION");

print!("... {pkg_version} ...");

and another nit: FWIW, env! is const, so this could be still just a usage
str constant (e.g., using concat!), but not that relevant and in this
relatively big single-file source it might be nicer to have it as function
– so fine by me as is.




More information about the pmg-devel mailing list