diff --git a/crates/hyperlog-tui/src/core_state.rs b/crates/hyperlog-tui/src/core_state.rs index ef50f0e..2017bcd 100644 --- a/crates/hyperlog-tui/src/core_state.rs +++ b/crates/hyperlog-tui/src/core_state.rs @@ -1,3 +1,5 @@ +use std::path::PathBuf; + use tonic::transport::{Channel, ClientTlsConfig}; use crate::{ @@ -14,15 +16,18 @@ pub struct State { } pub enum Backend { - Local, + Local { path_override: Option }, Remote { url: String }, } impl State { pub async fn new(backend: Backend) -> anyhow::Result { let (querier, commander) = match &backend { - Backend::Local => { - let storage = Storage::new(); + Backend::Local { path_override } => { + let mut storage = Storage::new(); + if let Some(path_override) = path_override { + storage.with_base(path_override); + } let engine = storage.load()?; let events = Events::default(); let engine = SharedEngine::from(engine); @@ -53,15 +58,21 @@ impl State { } pub fn unlock(&self) { - if let Backend::Local = &self.backend { - let storage = Storage::new(); + if let Backend::Local { path_override } = &self.backend { + let mut storage = Storage::new(); + if let Some(path_override) = path_override { + storage.with_base(path_override); + } storage.clear_lock_file(); } } pub fn info(&self) -> Option> { - if let Backend::Local = &self.backend { - let storage = Storage::new(); + if let Backend::Local { path_override } = &self.backend { + let mut storage = Storage::new(); + if let Some(path_override) = path_override { + storage.with_base(path_override); + } return Some(storage.info()); } diff --git a/crates/hyperlog/src/cli.rs b/crates/hyperlog/src/cli.rs index 9915e11..81c2a36 100644 --- a/crates/hyperlog/src/cli.rs +++ b/crates/hyperlog/src/cli.rs @@ -1,3 +1,5 @@ +use std::path::PathBuf; + use clap::{Parser, Subcommand, ValueEnum}; use hyperlog_tui::{ commander, @@ -15,6 +17,9 @@ struct Command { #[arg(long = "backend-url", required_if_eq("backend", "remote"))] backend_url: Option, + + #[arg(long = "local-path")] + local_path: Option, } #[derive(ValueEnum, Clone)] @@ -90,7 +95,9 @@ pub async fn execute() -> anyhow::Result<()> { let backend_url = cli.backend_url; let backend = match backend { - BackendArg::Local => Backend::Local, + BackendArg::Local => Backend::Local { + path_override: cli.local_path.clone(), + }, BackendArg::Remote => Backend::Remote { url: backend_url.expect("backend-url to be set"), },