add --list-sep

This commit is contained in:
figsoda 2023-01-02 16:48:50 -05:00
parent be1ef9d3c1
commit afae462b3f
2 changed files with 20 additions and 2 deletions

View File

@ -70,6 +70,11 @@ pub struct Opts {
/// List all fetchers that can be generated without --fetcher
#[arg(short = 'L', long, group = "command")]
pub list_possible_fetchers: bool,
/// Print out the listed fetchers with the specified separator,
/// only used when --list-fetchers or --list-possible-fetchers is specified
#[arg(short = 's', long, value_name = "SEPERATOR")]
pub list_sep: Option<String>,
}
#[derive(Clone, Debug, ValueEnum)]

View File

@ -32,11 +32,24 @@ fn main() -> Result<()> {
if opts.list_fetchers || opts.list_possible_fetchers {
let mut out = stdout().lock();
for fetcher in FetcherFunction::value_variants() {
if let Some(fetcher) = fetcher.to_possible_value() {
let fetchers = FetcherFunction::value_variants()
.iter()
.filter_map(ValueEnum::to_possible_value);
if let Some(sep) = opts.list_sep {
let mut fetchers = fetchers;
if let Some(fetcher) = fetchers.next() {
write!(out, "{}", fetcher.get_name())?;
}
for fetcher in fetchers {
write!(out, "{}{}", sep, fetcher.get_name())?;
}
} else {
for fetcher in fetchers {
writeln!(out, "{}", fetcher.get_name())?;
}
}
return Ok(());
}