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 BAA939C6D5 for ; Tue, 24 Oct 2023 14:55:24 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 9CB6E8324 for ; Tue, 24 Oct 2023 14:55:24 +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 ; Tue, 24 Oct 2023 14:55:23 +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 4C74744B67 for ; Tue, 24 Oct 2023 14:55:23 +0200 (CEST) From: Dominik Csapak To: pmg-devel@lists.proxmox.com Date: Tue, 24 Oct 2023 14:55:21 +0200 Message-Id: <20231024125521.769887-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. [options.to, options.host, main.rs] Subject: [pmg-devel] [PATCH log-tracker] 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: Tue, 24 Oct 2023 12:55:24 -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. It has almost all features we need (except producing help output), but wihout any dependencies. This increases 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. Signed-off-by: Dominik Csapak --- 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..45b0eca 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() { + println!( + "\ +pmg-log-tracker {} +Proxmox Mailgateway Log Tracker. Tool to scan mail logs. + +USAGE: + pmg-log-tracker [OPTIONS] + +OPTIONS: + -e, --endtime