diff options
author | Melody Horn <melody@boringcactus.com> | 2021-04-22 03:26:33 -0600 |
---|---|---|
committer | Melody Horn <melody@boringcactus.com> | 2021-04-22 03:26:33 -0600 |
commit | 8c1666c1a64201f8a12e125e3c63a83f4dbf7069 (patch) | |
tree | aee0eb35952a1e7da7d3b03a4b91c4f1e5aa2634 /src/state.rs | |
parent | 0b1563bc56cf20f8a63d5b90783294a1eb11ea17 (diff) | |
download | gityeet-8c1666c1a64201f8a12e125e3c63a83f4dbf7069.tar.gz gityeet-8c1666c1a64201f8a12e125e3c63a83f4dbf7069.zip |
throw together a super basic repo list
Diffstat (limited to 'src/state.rs')
-rw-r--r-- | src/state.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/state.rs b/src/state.rs new file mode 100644 index 0000000..1a88929 --- /dev/null +++ b/src/state.rs @@ -0,0 +1,24 @@ +use std::io; +use std::path::Path; + +use async_std::prelude::*; +use async_std::fs::read_dir; + +use git2::Repository; + +pub struct State { + pub data: Vec<Repository>, +} + +impl State { + pub async fn discover(root: impl AsRef<Path>) -> io::Result<Self> { + let root = root.as_ref(); + let dir = read_dir(root).await?; + let data = dir + .filter_map(|subdir| { + subdir.ok().and_then(|subdir| Repository::open_bare(&subdir.path()).ok()) + }) + .collect().await; + Ok(Self { data }) + } +} |