From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 2FF179D148 for ; Wed, 25 Oct 2023 13:20:30 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 11A79134D9 for ; Wed, 25 Oct 2023 13:20:30 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Wed, 25 Oct 2023 13:20:28 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 428DC45C87 for ; Wed, 25 Oct 2023 13:20:28 +0200 (CEST) From: Dominik Csapak To: pmg-devel@lists.proxmox.com Date: Wed, 25 Oct 2023 13:20:26 +0200 Message-Id: <20231025112026.4109852-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.012 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [proxmox.com, options.host, options.to, main.rs] Subject: [pmg-devel] [PATCH log-tracker v2] use pico-args instead of clap X-BeenThere: pmg-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Mail Gateway development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Oct 2023 11:20:30 -0000 Instead of upgrading from clap3 to clap4 (which seems to change their interface every year or so), switch to the much smaller pico-args. (Same as we did for termproxy recently, see [0]) It has almost all features we need (except producing help output) and supports OsString, but wihout any dependencies. This decreases compile time and reduces the 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. 0: https://git.proxmox.com/?p=pve-xtermjs.git;a=commitdiff;h=24d707d0506b120a085b06b5f2b6000696879a1e Signed-off-by: Dominik Csapak --- changes from v1: * extracted the pkg_version into a variable for interpolated use * improved commit message, e.g. by referencing the termproxy commit Cargo.toml | 2 +- src/main.rs | 223 +++++++++++++++++++--------------------------------- 2 files changed, 83 insertions(+), 142 deletions(-) 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" ] [dependencies] anyhow = "1" -clap = { version = "3.2.23", features = ["cargo"] } flate2 = "1.0" libc = "0.2" proxmox-time = "1.1" +pico-args = { version = "0.4", features = ["combined-flags"] } diff --git a/src/main.rs b/src/main.rs index e55f17b..e7aeeb4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,111 +13,55 @@ use anyhow::{bail, Error}; use flate2::read; use libc::time_t; -use clap::{App, Arg}; - mod time; use time::{Tm, CAL_MTOD}; +fn print_usage() { + let pkg_version = env!("CARGO_PKG_VERSION"); + println!( + "\ +pmg-log-tracker {pkg_version} +Proxmox Mailgateway Log Tracker. Tool to scan mail logs. + +USAGE: + pmg-log-tracker [OPTIONS] + +OPTIONS: + -e, --endtime