flavours/operations/
list.rs1use anyhow::{anyhow, Result};
2use std::path::Path;
3
4use crate::find::find_schemes;
5
6pub fn list(
14 patterns: Vec<&str>,
15 base_dir: &Path,
16 config_dir: &Path,
17 _verbose: bool,
18 lines: bool,
19) -> Result<()> {
20 let mut schemes = Vec::new();
21 for pattern in patterns {
22 let found_schemes = find_schemes(pattern, base_dir, config_dir)?;
23
24 for found_scheme in found_schemes {
25 schemes.push(String::from(
26 found_scheme
27 .file_stem()
28 .ok_or_else(|| anyhow!("Couldn't get scheme name"))?
29 .to_str()
30 .ok_or_else(|| anyhow!("Couldn't convert name"))?,
31 ));
32 }
33 }
34 schemes.sort();
35 schemes.dedup();
36
37 if schemes.is_empty() {
38 return Err(anyhow!("No matching scheme found"));
39 };
40
41 for scheme in &schemes {
42 print!("{}", scheme);
44 if lines {
45 println!();
47 } else {
48 print!(" ");
50 }
51 }
52 if !lines {
54 println!();
55 }
56
57 Ok(())
58}