28 lines
No EOL
775 B
Rust
28 lines
No EOL
775 B
Rust
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
|
|
}
|
|
} |