From 8c1666c1a64201f8a12e125e3c63a83f4dbf7069 Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Thu, 22 Apr 2021 03:26:33 -0600 Subject: throw together a super basic repo list --- src/state.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/state.rs (limited to 'src/state.rs') 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, +} + +impl State { + pub async fn discover(root: impl AsRef) -> io::Result { + 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 }) + } +} -- cgit v1.2.3