mirror of
https://github.com/nix-community/nurl.git
synced 2024-09-11 10:10:39 +03:00
add --list-sep
This commit is contained in:
parent
be1ef9d3c1
commit
afae462b3f
@ -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)]
|
||||
|
17
src/main.rs
17
src/main.rs
@ -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(());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user