git_workspace/commands/
list.rs

1use crate::lockfile::Lockfile;
2use anyhow::Context;
3use std::path::Path;
4
5/// List the contents of our workspace
6pub fn list(workspace: &Path, full: bool) -> anyhow::Result<()> {
7    // Read and parse the lockfile
8    let lockfile = Lockfile::new(workspace.join("workspace-lock.toml"));
9    let repositories = lockfile.read().context("Error reading lockfile")?;
10    let existing_repositories = repositories.iter().filter(|r| r.exists(workspace));
11    for repo in existing_repositories {
12        if full {
13            println!("{}", repo.get_path(workspace).unwrap().display());
14        } else {
15            println!("{}", repo.name());
16        }
17    }
18    Ok(())
19}