Skip to content

Commit

Permalink
Restructuration of the code to factor out the storage_config.
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuDutSik committed Nov 12, 2024
1 parent dcf2a5b commit 0253125
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
14 changes: 14 additions & 0 deletions linera-client/src/client_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,20 @@ pub enum DatabaseToolCommand {
},
}

impl DatabaseToolCommand {
pub fn storage_config(&self) -> Result<StorageConfigNamespace, Error> {
let storage_config = match self {
DatabaseToolCommand::DeleteAll { storage_config } => storage_config,
DatabaseToolCommand::DeleteNamespace { storage_config } => storage_config,
DatabaseToolCommand::CheckExistence { storage_config } => storage_config,
DatabaseToolCommand::CheckAbsence { storage_config } => storage_config,
DatabaseToolCommand::Initialize { storage_config } => storage_config,
DatabaseToolCommand::ListNamespaces { storage_config } => storage_config,
};
Ok(storage_config.parse::<StorageConfigNamespace>()?)
}
}

#[derive(Clone, clap::Parser)]
pub enum NetCommand {
/// Start a Local Linera Network
Expand Down
34 changes: 9 additions & 25 deletions linera-service/src/linera/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use linera_client::{
},
config::{CommitteeConfig, GenesisConfig},
persistent::{self, Persist},
storage::{Runnable, StorageConfigNamespace},
storage::Runnable,
wallet::{UserChain, Wallet},
};
use linera_core::{
Expand Down Expand Up @@ -1559,24 +1559,17 @@ async fn run(options: &ClientOptions) -> Result<i32, anyhow::Error> {
},

ClientCommand::Storage(command) => {
let storage_config = command.storage_config()?;
let common_config = CommonStoreConfig::default();
let full_storage_config = storage_config.add_common_config(common_config).await?;
match command {
DatabaseToolCommand::DeleteAll { storage_config } => {
let storage_config = storage_config.parse::<StorageConfigNamespace>()?;
let full_storage_config =
storage_config.add_common_config(common_config).await?;
DatabaseToolCommand::DeleteAll { .. } => {
full_storage_config.delete_all().await?;
}
DatabaseToolCommand::DeleteNamespace { storage_config } => {
let storage_config = storage_config.parse::<StorageConfigNamespace>()?;
let full_storage_config =
storage_config.add_common_config(common_config).await?;
DatabaseToolCommand::DeleteNamespace { .. } => {
full_storage_config.delete_namespace().await?;
}
DatabaseToolCommand::CheckExistence { storage_config } => {
let storage_config = storage_config.parse::<StorageConfigNamespace>()?;
let full_storage_config =
storage_config.add_common_config(common_config).await?;
DatabaseToolCommand::CheckExistence { .. } => {
let test = full_storage_config.test_existence().await?;
if test {
tracing::info!("The database does exist");
Expand All @@ -1586,10 +1579,7 @@ async fn run(options: &ClientOptions) -> Result<i32, anyhow::Error> {
return Ok(1);
}
}
DatabaseToolCommand::CheckAbsence { storage_config } => {
let storage_config = storage_config.parse::<StorageConfigNamespace>()?;
let full_storage_config =
storage_config.add_common_config(common_config).await?;
DatabaseToolCommand::CheckAbsence { .. } => {
let test = full_storage_config.test_existence().await?;
if test {
tracing::info!("The database does exist");
Expand All @@ -1599,16 +1589,10 @@ async fn run(options: &ClientOptions) -> Result<i32, anyhow::Error> {
return Ok(0);
}
}
DatabaseToolCommand::Initialize { storage_config } => {
let storage_config = storage_config.parse::<StorageConfigNamespace>()?;
let full_storage_config =
storage_config.add_common_config(common_config).await?;
DatabaseToolCommand::Initialize { .. } => {
full_storage_config.initialize().await?;
}
DatabaseToolCommand::ListNamespaces { storage_config } => {
let storage_config = storage_config.parse::<StorageConfigNamespace>()?;
let full_storage_config =
storage_config.add_common_config(common_config).await?;
DatabaseToolCommand::ListNamespaces { .. } => {
let namespaces = full_storage_config.list_all().await?;
println!("The list of namespaces is {:?}", namespaces);
}
Expand Down

0 comments on commit 0253125

Please sign in to comment.