Move RpcConfig from desktop to core

This commit is contained in:
fluo10 2025-08-14 08:02:00 +09:00
parent 29ddd61eec
commit 8f04832397
5 changed files with 45 additions and 6 deletions

View file

@ -1,6 +1,7 @@
pub mod error;
mod storage;
mod p2p;
mod rpc;
use std::path::Path;
use crate::{utils::{emptiable::Emptiable, mergeable::Mergeable}};
@ -10,6 +11,10 @@ use serde::{de::DeserializeOwned, Deserialize, Serialize};
use tokio::{fs::File, io::{AsyncReadExt, AsyncWriteExt}};
pub use storage::{StorageConfig, PartialStorageConfig};
pub use p2p::{P2pConfig, PartialP2pConfig};
pub use rpc::*;
#[cfg(feature="desktop")]
use clap::Args;
pub trait Config: TryFrom<Self::PartialConfig>{
type PartialConfig: PartialConfig<Config = Self>;
@ -19,8 +24,25 @@ pub trait PartialConfig: Emptiable + From<Self::Config> + Mergeable {
}
pub trait BaseConfig: DeserializeOwned + Serialize {
fn new() -> Self;
#[cfg_attr(feature="desktop", derive(Args))]
#[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> {
toml::from_str(s)
}
@ -62,6 +84,7 @@ pub trait BaseConfig: DeserializeOwned + Serialize {
}
}
#[cfg(test)]
mod tests {
use serde::{Deserialize, Serialize};

View file

@ -1,6 +1,7 @@
use std::{net::{IpAddr, Ipv4Addr, SocketAddr, TcpListener}, path::PathBuf};
#[cfg(feature="desktop")]
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 serde::{Deserialize, Serialize};

View 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!()
}
}

View file

View file

@ -9,8 +9,8 @@ pub struct Cli {
#[derive(Debug, Subcommand)]
pub enum CliCommand {
Config(ConfigCommandArgs),
Device(DeviceCommandArgs),
Log(LogCommandArgs),
//Config(ConfigCommandArgs),
//Device(DeviceCommandArgs),
//Log(LogCommandArgs),
Server(ServerCommandArgs),
}