Move RpcConfig from desktop to core
This commit is contained in:
parent
29ddd61eec
commit
8f04832397
5 changed files with 45 additions and 6 deletions
|
@ -1,6 +1,7 @@
|
||||||
pub mod error;
|
pub mod error;
|
||||||
mod storage;
|
mod storage;
|
||||||
mod p2p;
|
mod p2p;
|
||||||
|
mod rpc;
|
||||||
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use crate::{utils::{emptiable::Emptiable, mergeable::Mergeable}};
|
use crate::{utils::{emptiable::Emptiable, mergeable::Mergeable}};
|
||||||
|
@ -10,6 +11,10 @@ use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||||
use tokio::{fs::File, io::{AsyncReadExt, AsyncWriteExt}};
|
use tokio::{fs::File, io::{AsyncReadExt, AsyncWriteExt}};
|
||||||
pub use storage::{StorageConfig, PartialStorageConfig};
|
pub use storage::{StorageConfig, PartialStorageConfig};
|
||||||
pub use p2p::{P2pConfig, PartialP2pConfig};
|
pub use p2p::{P2pConfig, PartialP2pConfig};
|
||||||
|
pub use rpc::*;
|
||||||
|
|
||||||
|
#[cfg(feature="desktop")]
|
||||||
|
use clap::Args;
|
||||||
|
|
||||||
pub trait Config: TryFrom<Self::PartialConfig>{
|
pub trait Config: TryFrom<Self::PartialConfig>{
|
||||||
type PartialConfig: PartialConfig<Config = Self>;
|
type PartialConfig: PartialConfig<Config = Self>;
|
||||||
|
@ -19,8 +24,25 @@ pub trait PartialConfig: Emptiable + From<Self::Config> + Mergeable {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait BaseConfig: DeserializeOwned + Serialize {
|
#[cfg_attr(feature="desktop", derive(Args))]
|
||||||
fn new() -> Self;
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
pub struct BaseConfig {
|
||||||
|
#[cfg_attr(feature="desktop", command(flatten))]
|
||||||
|
p2p: PartialP2pConfig,
|
||||||
|
#[cfg_attr(feature="desktop", command(flatten))]
|
||||||
|
storage: PartialStorageConfig,
|
||||||
|
#[cfg_attr(feature="desktop", command(flatten))]
|
||||||
|
rpc: PartialRpcConfig,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BaseConfig {
|
||||||
|
fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
p2p : PartialP2pConfig::empty().with_new_secret(),
|
||||||
|
storage: PartialStorageConfig::empty(),
|
||||||
|
rpc: PartialRpcConfig::empty().with_unused_port(),
|
||||||
|
}
|
||||||
|
}
|
||||||
fn from_toml(s: &str) -> Result<Self, toml::de::Error> {
|
fn from_toml(s: &str) -> Result<Self, toml::de::Error> {
|
||||||
toml::from_str(s)
|
toml::from_str(s)
|
||||||
}
|
}
|
||||||
|
@ -62,6 +84,7 @@ pub trait BaseConfig: DeserializeOwned + Serialize {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use std::{net::{IpAddr, Ipv4Addr, SocketAddr, TcpListener}, path::PathBuf};
|
use std::{net::{IpAddr, Ipv4Addr, SocketAddr, TcpListener}, path::PathBuf};
|
||||||
|
#[cfg(feature="desktop")]
|
||||||
use clap::Args;
|
use clap::Args;
|
||||||
use caretta_core::{config::PartialConfig, utils::{emptiable::Emptiable, mergeable::Mergeable}};
|
use crate::{config::PartialConfig, utils::{emptiable::Emptiable, mergeable::Mergeable}};
|
||||||
use libp2p::mdns::Config;
|
use libp2p::mdns::Config;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
15
desktop/src/cli/peer/list.rs
Normal file
15
desktop/src/cli/peer/list.rs
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
use clap::Args;
|
||||||
|
use crate::utils::runnable::Runnable;
|
||||||
|
use crate::cli::{ConfigArgs, RunnableCommand};
|
||||||
|
|
||||||
|
#[derive(Debug, Args)]
|
||||||
|
pub struct DeviceListCommandArgs{
|
||||||
|
#[command(flatten)]
|
||||||
|
config: ConfigArgs
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Runnable for DeviceListCommandArgs {
|
||||||
|
async fn run(self) {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
0
desktop/src/cli/peer/mod.rs
Normal file
0
desktop/src/cli/peer/mod.rs
Normal file
|
@ -9,8 +9,8 @@ pub struct Cli {
|
||||||
|
|
||||||
#[derive(Debug, Subcommand)]
|
#[derive(Debug, Subcommand)]
|
||||||
pub enum CliCommand {
|
pub enum CliCommand {
|
||||||
Config(ConfigCommandArgs),
|
//Config(ConfigCommandArgs),
|
||||||
Device(DeviceCommandArgs),
|
//Device(DeviceCommandArgs),
|
||||||
Log(LogCommandArgs),
|
//Log(LogCommandArgs),
|
||||||
Server(ServerCommandArgs),
|
Server(ServerCommandArgs),
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue