From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 102351FF15E for ; Fri, 18 Oct 2024 13:59:25 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 5682F3189A; Fri, 18 Oct 2024 13:59:53 +0200 (CEST) From: Christoph Heiss To: pve-devel@lists.proxmox.com Date: Fri, 18 Oct 2024 13:59:38 +0200 Message-ID: <20241018115943.813243-3-c.heiss@proxmox.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241018115943.813243-1-c.heiss@proxmox.com> References: <20241018115943.813243-1-c.heiss@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.030 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 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. 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. [main.rs] Subject: [pve-devel] [PATCH installer 2/4] fetch-answer: refactor cli argument parsing X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" Clean up the actual parsing a bit to make it more easily extensible, and add a proper help menu. Signed-off-by: Christoph Heiss --- proxmox-fetch-answer/src/main.rs | 40 +++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/proxmox-fetch-answer/src/main.rs b/proxmox-fetch-answer/src/main.rs index 86c3270..753ab29 100644 --- a/proxmox-fetch-answer/src/main.rs +++ b/proxmox-fetch-answer/src/main.rs @@ -16,6 +16,22 @@ mod fetch_plugins; static LOGGER: AutoInstLogger = AutoInstLogger; static AUTOINST_MODE_FILE: &str = "/cdrom/auto-installer-mode.toml"; +const CLI_USAGE_HELPTEXT: &str = concat!( + "Usage: ", + env!("CARGO_BIN_NAME"), + " + +Commands: + iso Fetch the builtin answer file from the ISO + http Fetch the answer file via HTTP(S) + Additional parameters: [] [] + partition Fetch the answer file from a mountable partition + +Options: + -h, --help Print this help menu +" +); + pub fn init_log() -> Result<()> { AutoInstLogger::init("/tmp/fetch_answer.log")?; log::set_logger(&LOGGER) @@ -46,21 +62,27 @@ fn fetch_answer(install_settings: &AutoInstSettings) -> Result { } fn settings_from_cli_args(args: &[String]) -> Result { - // TODO: this was done in a bit of a hurry, needs tidying up let mode = match args[1].to_lowercase().as_str() { "iso" => FetchAnswerFrom::Iso, "http" => FetchAnswerFrom::Http, "partition" => FetchAnswerFrom::Partition, - "-h" | "--help" => bail!( - "usage: {} [] []", - args[0] - ), + "-h" | "--help" => { + eprintln!("{}", CLI_USAGE_HELPTEXT); + bail!("invalid usage"); + } _ => bail!("failed to parse fetch-from argument, not one of 'http', 'iso', or 'partition'"), }; - if args.len() > 4 { - } else if args.len() > 2 && mode != FetchAnswerFrom::Http { - bail!("only 'http' fetch-from mode supports additional url and cert-fingerprint mode"); - } + + match mode { + FetchAnswerFrom::Iso | FetchAnswerFrom::Partition if args.len() > 2 => { + bail!("'iso' and 'partition' modes do not take any additional arguments") + } + FetchAnswerFrom::Http if args.len() > 4 => { + bail!("'http' mode takes at most 2 additional arguments") + } + _ => {} + }; + Ok(AutoInstSettings { mode, partition_label: "proxmox-ais".to_owned(), -- 2.46.0 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel