mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-24 08:56:43 +02:00
use StorageConfig instead of ReplicaConfig
This commit is contained in:
parent
b004b6cb93
commit
02d9c577ab
6 changed files with 30 additions and 21 deletions
|
@ -3,7 +3,7 @@
|
||||||
use crate::argparse::{Command, Subcommand};
|
use crate::argparse::{Command, Subcommand};
|
||||||
use config::Config;
|
use config::Config;
|
||||||
use failure::{format_err, Fallible};
|
use failure::{format_err, Fallible};
|
||||||
use taskchampion::{Replica, ReplicaConfig, Server, ServerConfig, Uuid};
|
use taskchampion::{Replica, Server, ServerConfig, StorageConfig, Uuid};
|
||||||
use termcolor::{ColorChoice, StandardStream};
|
use termcolor::{ColorChoice, StandardStream};
|
||||||
|
|
||||||
mod cmd;
|
mod cmd;
|
||||||
|
@ -104,8 +104,8 @@ pub(crate) fn invoke(command: Command, settings: Config) -> Fallible<()> {
|
||||||
fn get_replica(settings: &Config) -> Fallible<Replica> {
|
fn get_replica(settings: &Config) -> Fallible<Replica> {
|
||||||
let taskdb_dir = settings.get_str("data_dir")?.into();
|
let taskdb_dir = settings.get_str("data_dir")?.into();
|
||||||
log::debug!("Replica data_dir: {:?}", taskdb_dir);
|
log::debug!("Replica data_dir: {:?}", taskdb_dir);
|
||||||
let replica_config = ReplicaConfig { taskdb_dir };
|
let storage_config = StorageConfig::OnDisk { taskdb_dir };
|
||||||
Ok(Replica::from_config(replica_config)?)
|
Ok(Replica::new(storage_config.into_storage()?))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the server for this invocation
|
/// Get the server for this invocation
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
/// The configuration required for a replica. Use with [`crate::Replica::from_config`].
|
|
||||||
pub struct ReplicaConfig {
|
|
||||||
/// Path containing the task DB.
|
|
||||||
pub taskdb_dir: PathBuf,
|
|
||||||
}
|
|
|
@ -31,7 +31,6 @@ for more information about the design and usage of the tool.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
mod config;
|
|
||||||
mod errors;
|
mod errors;
|
||||||
mod replica;
|
mod replica;
|
||||||
pub mod server;
|
pub mod server;
|
||||||
|
@ -41,9 +40,9 @@ mod taskdb;
|
||||||
mod utils;
|
mod utils;
|
||||||
mod workingset;
|
mod workingset;
|
||||||
|
|
||||||
pub use config::ReplicaConfig;
|
|
||||||
pub use replica::Replica;
|
pub use replica::Replica;
|
||||||
pub use server::{Server, ServerConfig};
|
pub use server::{Server, ServerConfig};
|
||||||
|
pub use storage::StorageConfig;
|
||||||
pub use task::{Priority, Status, Tag, Task, TaskMut};
|
pub use task::{Priority, Status, Tag, Task, TaskMut};
|
||||||
pub use workingset::WorkingSet;
|
pub use workingset::WorkingSet;
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
use crate::config::ReplicaConfig;
|
|
||||||
use crate::errors::Error;
|
use crate::errors::Error;
|
||||||
use crate::server::Server;
|
use crate::server::Server;
|
||||||
|
use crate::storage::{Operation, Storage, TaskMap};
|
||||||
use crate::task::{Status, Task};
|
use crate::task::{Status, Task};
|
||||||
use crate::taskdb::TaskDB;
|
use crate::taskdb::TaskDB;
|
||||||
use crate::storage::{KVStorage, Operation, TaskMap, Storage};
|
|
||||||
use crate::workingset::WorkingSet;
|
use crate::workingset::WorkingSet;
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use failure::Fallible;
|
use failure::Fallible;
|
||||||
|
@ -36,13 +35,6 @@ impl Replica {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a new replica from a configuration object. This is the common way
|
|
||||||
/// to create a new object.
|
|
||||||
pub fn from_config(config: ReplicaConfig) -> Fallible<Replica> {
|
|
||||||
let storage = Box::new(KVStorage::new(config.taskdb_dir)?);
|
|
||||||
Ok(Replica::new(storage))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub fn new_inmemory() -> Replica {
|
pub fn new_inmemory() -> Replica {
|
||||||
Replica::new(Box::new(crate::storage::InMemoryStorage::new()))
|
Replica::new(Box::new(crate::storage::InMemoryStorage::new()))
|
||||||
|
|
23
taskchampion/src/storage/config.rs
Normal file
23
taskchampion/src/storage/config.rs
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
use super::{InMemoryStorage, KVStorage, Storage};
|
||||||
|
use failure::Fallible;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
/// The configuration required for a replica's storage.
|
||||||
|
pub enum StorageConfig {
|
||||||
|
/// Store the data on disk. This is the common choice.
|
||||||
|
OnDisk {
|
||||||
|
/// Path containing the task DB.
|
||||||
|
taskdb_dir: PathBuf,
|
||||||
|
},
|
||||||
|
/// Store the data in memory. This is only useful for testing.
|
||||||
|
InMemory,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl StorageConfig {
|
||||||
|
pub fn into_storage(self) -> Fallible<Box<dyn Storage>> {
|
||||||
|
Ok(match self {
|
||||||
|
StorageConfig::OnDisk { taskdb_dir } => Box::new(KVStorage::new(taskdb_dir)?),
|
||||||
|
StorageConfig::InMemory => Box::new(InMemoryStorage::new()),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,11 +2,13 @@ use failure::Fallible;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
mod config;
|
||||||
mod inmemory;
|
mod inmemory;
|
||||||
mod kv;
|
mod kv;
|
||||||
mod operation;
|
mod operation;
|
||||||
|
|
||||||
pub use self::kv::KVStorage;
|
pub use self::kv::KVStorage;
|
||||||
|
pub use config::StorageConfig;
|
||||||
pub use inmemory::InMemoryStorage;
|
pub use inmemory::InMemoryStorage;
|
||||||
|
|
||||||
pub use operation::Operation;
|
pub use operation::Operation;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue