1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use std::{
net::{AddrParseError, IpAddr, SocketAddr},
path::{Path, PathBuf},
};
use clap::Parser;
#[derive(Parser, Debug)]
pub struct Args {
/// Whether podsync's clients connect to it over https.
/// If so, the sessionid cookie is sent as a secure cookie.
#[arg(short, long)]
secure: bool,
/// The address podsync should listen on. By default
/// podsync will listen just on the IPv4 loopback.
#[arg(short, long)]
address: Option<String>,
/// The location of the data directory. By default
/// this is the current working directory.
#[arg(short, long)]
data_dir: Option<PathBuf>,
/// The port podsync listens on.
#[arg(short, long, default_value_t = 80)]
port: u16,
/// Emit the podsync version
#[arg(short, long)]
version: bool,
}
impl Args {
pub fn addr(&self) -> Result<SocketAddr, AddrParseError> {
self.address
.as_deref()
.unwrap_or("127.0.0.1")
.parse()
.map(|addr: IpAddr| (addr, self.port).into())
}
pub fn secure(&self) -> bool {
self.secure
}
pub fn show_version(&self) -> bool {
self.version
}
pub fn data_dir(&self) -> Option<&Path> {
self.data_dir.as_deref()
}
}