irongit

The dotfiles manager.

feat: dotman list

huncholanehuncholaneauthored
parent 0357256commit a46583c1a45070604c473ca36877815525695151Browse files

1 file changed, +26 -0

+26-0src/main.rs
@@ -26,6 +26,8 @@ enum Commands {
2626 Update,
2727 /// List active links in ~/.config that point into dotman
2828 Active,
29+ /// List repositories installed in the dotman store
30+ List,
2931 /// Generate shell completions to stdout (bash|zsh|fish|powershell|elvish)
3032 Completions { shell: Shell },
3133 }
@@ -61,6 +63,7 @@ fn main() -> Result<()> {
6163 Commands::Link(args) => cmd_link(&args.name, &args.target),
6264 Commands::Update => cmd_update(),
6365 Commands::Active => cmd_active(),
66+ Commands::List => cmd_list(),
6467 Commands::Completions { shell } => cmd_completions(shell),
6568 }
6669 }
@@ -304,3 +307,26 @@ fn cmd_active() -> Result<()> {
304307 }
305308 Ok(())
306309 }
310+
311+fn cmd_list() -> Result<()> {
312+ ensure_dotman_dir()?;
313+ let root = Path::new(DOTMAN_DIR);
314+ let mut repos: Vec<String> = Vec::new();
315+ for entry in fs::read_dir(root).with_context(|| format!("Reading {}", DOTMAN_DIR))? {
316+ let entry = entry?;
317+ let path = entry.path();
318+ if !path.is_dir() { continue; }
319+ let name = match path.file_name().and_then(|s| s.to_str()) {
320+ Some(s) => s.to_string(),
321+ None => continue,
322+ };
323+ repos.push(name);
324+ }
325+ repos.sort();
326+ if repos.is_empty() {
327+ println!("No repositories installed in {}.", DOTMAN_DIR);
328+ } else {
329+ for r in repos { println!("{}", r); }
330+ }
331+ Ok(())
332+}