aboutsummaryrefslogtreecommitdiff
path: root/src/state.rs
blob: 1a88929982943f6a7cdb9b1639bb3ac2e9e17fda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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 })
    }
}