From e03d2cdff629e1f0604396b1d02c0ecb71bcb610 Mon Sep 17 00:00:00 2001 From: Dongsu Park Date: Tue, 14 Nov 2023 18:32:19 +0100 Subject: [PATCH 1/2] Set number of args to 0 for no-replace and list In case of clap 4, it is necessary to set the number of args to 0, if the option does not take any parameter. --- src/main.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.rs b/src/main.rs index c0e2a6f..afccd38 100644 --- a/src/main.rs +++ b/src/main.rs @@ -196,11 +196,13 @@ fn config() -> Result { .arg( Arg::new("no-replace") .short('n') + .num_args(0) .help("When adding, don't replace an existing key with the given name."), ) .arg( Arg::new("list") .short('l') + .num_args(0) .help("List the names and number of keys currently installed."), ) .arg( From 2584dbd397890646927cc66a72b7bbf57bde2c57 Mon Sep 17 00:00:00 2001 From: Dongsu Park Date: Wed, 15 Nov 2023 18:14:58 +0100 Subject: [PATCH 2/2] print out list only in case given by user List of the current keys should be printed only when the user specified the option --list. If not, simply only sync. --- src/main.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index afccd38..5019f81 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,6 +24,7 @@ extern crate uzers; extern crate update_ssh_keys; +use clap::parser::ValueSource; use clap::{crate_version, Arg, Command}; use std::fs::File; use std::path::PathBuf; @@ -271,7 +272,11 @@ fn config() -> Result { .map(|name| UssCommand::Disable { name: name.into() }) }) .unwrap_or(if matches.contains_id("list") { - UssCommand::List + if matches.value_source("list") == Some(ValueSource::CommandLine) { + UssCommand::List + } else { + UssCommand::Sync + } } else { UssCommand::Sync });