Skip to content

Commit

Permalink
Merge pull request #16 from flatcar/dongsu/clap4-fix-short-options
Browse files Browse the repository at this point in the history
Set number of args to 0 for no-replace and list
  • Loading branch information
dongsupark authored Nov 16, 2023
2 parents b1c8362 + 2584dbd commit 2a2aa89
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -196,11 +197,13 @@ fn config() -> Result<Config> {
.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(
Expand Down Expand Up @@ -269,7 +272,11 @@ fn config() -> Result<Config> {
.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
});
Expand Down

0 comments on commit 2a2aa89

Please sign in to comment.