refactor: let state use either local or backend
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
@@ -1,13 +1,34 @@
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
use hyperlog_tui::{commander, core_state::State};
|
||||
use clap::{Parser, Subcommand, ValueEnum};
|
||||
use hyperlog_tui::{
|
||||
commander,
|
||||
core_state::{Backend, State},
|
||||
};
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
struct Command {
|
||||
#[command(subcommand)]
|
||||
command: Option<Commands>,
|
||||
|
||||
#[arg(long, default_value = "local")]
|
||||
backend: BackendArg,
|
||||
}
|
||||
|
||||
#[derive(ValueEnum, Clone)]
|
||||
enum BackendArg {
|
||||
Local,
|
||||
Remote,
|
||||
}
|
||||
|
||||
impl From<BackendArg> for Backend {
|
||||
fn from(value: BackendArg) -> Self {
|
||||
match value {
|
||||
BackendArg::Local => Backend::Local,
|
||||
BackendArg::Remote => Backend::Remote,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
@@ -73,6 +94,8 @@ pub async fn execute() -> anyhow::Result<()> {
|
||||
tracing_subscriber::fmt::init();
|
||||
}
|
||||
|
||||
let backend = cli.backend;
|
||||
|
||||
match cli.command {
|
||||
#[cfg(feature = "include_server")]
|
||||
Some(Commands::Serve {
|
||||
@@ -90,7 +113,7 @@ pub async fn execute() -> anyhow::Result<()> {
|
||||
.await?;
|
||||
}
|
||||
Some(Commands::Exec { commands }) => {
|
||||
let state = State::new()?;
|
||||
let state = State::new(backend.into()).await?;
|
||||
match commands {
|
||||
ExecCommands::CreateRoot { root } => state
|
||||
.commander
|
||||
@@ -109,7 +132,7 @@ pub async fn execute() -> anyhow::Result<()> {
|
||||
}
|
||||
}
|
||||
Some(Commands::Query { commands }) => {
|
||||
let state = State::new()?;
|
||||
let state = State::new(backend.into()).await?;
|
||||
match commands {
|
||||
QueryCommands::Get { root, path } => {
|
||||
let res = state.querier.get(
|
||||
@@ -126,23 +149,23 @@ pub async fn execute() -> anyhow::Result<()> {
|
||||
}
|
||||
}
|
||||
Some(Commands::CreateRoot { name }) => {
|
||||
let state = State::new()?;
|
||||
let state = State::new(backend.into()).await?;
|
||||
state
|
||||
.commander
|
||||
.execute(commander::Command::CreateRoot { root: name })?;
|
||||
println!("Root was successfully created, now run:\n\n$ hyperlog");
|
||||
}
|
||||
Some(Commands::Info {}) => {
|
||||
let state = State::new()?;
|
||||
let state = State::new(backend.into()).await?;
|
||||
println!("graph stored at: {}", state.storage.info()?)
|
||||
}
|
||||
Some(Commands::ClearLock {}) => {
|
||||
let state = State::new()?;
|
||||
let state = State::new(backend.into()).await?;
|
||||
state.storage.clear_lock_file();
|
||||
println!("cleared lock file");
|
||||
}
|
||||
None => {
|
||||
let state = State::new()?;
|
||||
let state = State::new(backend.into()).await?;
|
||||
hyperlog_tui::execute(state).await?;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user