Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
c54fc3f4d0
commit
442ab64583
@ -196,6 +196,15 @@ impl Engine {
|
||||
|
||||
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 {
|
||||
|
@ -9,6 +9,10 @@ impl Querier {
|
||||
Self { engine }
|
||||
}
|
||||
|
||||
pub fn get_available_roots(&self) -> Option<Vec<String>> {
|
||||
self.engine.get_roots()
|
||||
}
|
||||
|
||||
pub fn get(
|
||||
&self,
|
||||
root: &str,
|
||||
|
@ -63,4 +63,8 @@ impl SharedEngine {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn get_roots(&self) -> Option<Vec<String>> {
|
||||
self.inner.read().unwrap().get_roots()
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,14 @@ pub async fn execute(state: State) -> 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());
|
||||
graph_explorer.update_graph()?;
|
||||
|
@ -28,6 +28,11 @@ enum Commands {
|
||||
},
|
||||
Info {},
|
||||
|
||||
CreateRoot {
|
||||
#[arg(long)]
|
||||
name: String,
|
||||
},
|
||||
|
||||
ClearLock {},
|
||||
}
|
||||
|
||||
@ -103,6 +108,12 @@ pub async fn execute() -> anyhow::Result<()> {
|
||||
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 {}) => {
|
||||
println!("graph stored at: {}", state.storage.info()?)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user