feat: add server cli configuration
This commit is contained in:
parent
143dc0e5ce
commit
f9fb8f0670
4 changed files with 234 additions and 15 deletions
28
server/src/config.rs
Normal file
28
server/src/config.rs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||
use std::path::PathBuf;
|
||||
use clap::Parser;
|
||||
|
||||
const LOCAL_IPV4: IpAddr = IpAddr::V4(Ipv4Addr::LOCALHOST);
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[command(author, version, about)]
|
||||
pub struct Configuration {
|
||||
#[arg(short, long, default_value_t = LOCAL_IPV4, help = "IP address for the server to listen on")]
|
||||
address: IpAddr,
|
||||
#[arg(short, long, default_value = "5432", help = "Port for the server to listen on")]
|
||||
port: u16,
|
||||
#[arg(short, long, help = "Path to the data file")]
|
||||
file: PathBuf,
|
||||
}
|
||||
|
||||
impl Configuration {
|
||||
#[inline]
|
||||
pub fn get_socket_address(&self) -> SocketAddr {
|
||||
SocketAddr::new(self.address, self.port)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_file_path(&self) -> &PathBuf {
|
||||
&self.file
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue