aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs47
1 files changed, 41 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs
index cb18c22..52dcaee 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,18 +1,53 @@
use askama::Template;
+use async_std::sync::{Arc, Mutex};
+use eyre::Result;
use tide::prelude::*;
+mod state;
+use state::State;
+use std::ops::Deref;
+
#[derive(Template)]
#[template(path = "index.html")]
-struct IndexTemplate;
+struct IndexTemplate<'a> {
+ state: &'a State,
+}
#[async_std::main]
-async fn main() -> tide::Result<()> {
- let mut app = tide::new();
+async fn main() -> Result<()> {
+ let matches = clap::App::new("gityeet")
+ .arg(clap::Arg::with_name("root")
+ .help("sets the directory from which repositories will be found")
+ .required(true))
+ .arg(clap::Arg::with_name("port")
+ .help("sets the port number")
+ .required(true))
+ .get_matches();
+
+ let root = matches.value_of("root").expect("root is required");
+ let port = matches.value_of("port").expect("port is required");
+ let port: u16 = port.parse().expect("port was not valid");
+
+ let state = State::discover(root).await?;
+ // unfortunately, the State has to be both Send and Sync, but git2::Repository is not Sync
+ // and even an Arc<RwLock<State>> isn't Sync if State isn't Sync, it has to be a Mutex to get Sync
+ // TODO do something smarter for that
+ let mut app = tide::with_state(Arc::new(Mutex::new(state)));
app.at("/").get(index);
- app.listen("127.0.0.1:8000").await?;
+ app.listen(("127.0.0.1", port)).await?;
Ok(())
}
-async fn index(_: tide::Request<()>) -> tide::Result {
- Ok(IndexTemplate.into())
+async fn index(req: tide::Request<Arc<Mutex<State>>>) -> tide::Result {
+ let state = req.state();
+ let state = state.lock_arc().await;
+ for repo in &state.data {
+ println!("path: {:?}", repo.path());
+ let head = repo.head();
+ if let Ok(head) = head {
+ println!("head name: {:?}", head.name());
+ println!("head shorthand: {:?}", head.shorthand());
+ }
+ }
+ Ok(IndexTemplate { state: state.deref() }.into())
}