feat: can create root
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2024-05-10 22:47:32 +02:00
parent c54fc3f4d0
commit 442ab64583
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912
5 changed files with 36 additions and 1 deletions

View File

@ -196,6 +196,15 @@ impl Engine {
Ok(()) Ok(())
} }
pub fn get_roots(&self) -> Option<Vec<String>> {
let items = self.graph.keys().cloned().collect::<Vec<_>>();
if items.is_empty() {
None
} else {
Some(items)
}
}
} }
impl Display for Engine { impl Display for Engine {

View File

@ -9,6 +9,10 @@ impl Querier {
Self { engine } Self { engine }
} }
pub fn get_available_roots(&self) -> Option<Vec<String>> {
self.engine.get_roots()
}
pub fn get( pub fn get(
&self, &self,
root: &str, root: &str,

View File

@ -63,4 +63,8 @@ impl SharedEngine {
Ok(()) Ok(())
} }
pub(crate) fn get_roots(&self) -> Option<Vec<String>> {
self.inner.read().unwrap().get_roots()
}
} }

View File

@ -39,7 +39,14 @@ pub async fn execute(state: State) -> Result<()> {
} }
fn run(terminal: &mut Terminal<CrosstermBackend<Stdout>>, state: SharedState) -> Result<()> { fn run(terminal: &mut Terminal<CrosstermBackend<Stdout>>, state: SharedState) -> Result<()> {
let root = "kjuulh".to_string(); let root = match state.querier.get_available_roots() {
// TODO: maybe present choose root screen
Some(roots) => roots.first().cloned().unwrap(),
None => {
// TODO: present create root screen
anyhow::bail!("no valid root available\nPlease run:\n\n$ hyperlog create-root --name <your-username>");
}
};
let mut graph_explorer = GraphExplorer::new(root.clone(), state.clone()); let mut graph_explorer = GraphExplorer::new(root.clone(), state.clone());
graph_explorer.update_graph()?; graph_explorer.update_graph()?;

View File

@ -28,6 +28,11 @@ enum Commands {
}, },
Info {}, Info {},
CreateRoot {
#[arg(long)]
name: String,
},
ClearLock {}, ClearLock {},
} }
@ -103,6 +108,12 @@ pub async fn execute() -> anyhow::Result<()> {
println!("{}", output); println!("{}", output);
} }
}, },
Some(Commands::CreateRoot { name }) => {
state
.commander
.execute(commander::Command::CreateRoot { root: name })?;
println!("Root was successfully created, now run:\n\n$ hyperlog");
}
Some(Commands::Info {}) => { Some(Commands::Info {}) => {
println!("graph stored at: {}", state.storage.info()?) println!("graph stored at: {}", state.storage.info()?)
} }