mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-05-07 02:09:06 +00:00
✨ feat: custom hostname
This commit is contained in:
@@ -111,6 +111,9 @@ struct Cli {
|
||||
#[arg(long, help = "directory to store log files")]
|
||||
file_log_dir: Option<String>,
|
||||
|
||||
#[arg(long, help = "host name to identify this device")]
|
||||
hostname: Option<String>,
|
||||
|
||||
#[arg(
|
||||
short = 'm',
|
||||
long,
|
||||
@@ -177,6 +180,26 @@ impl From<Cli> for TomlConfigLoader {
|
||||
let cfg = TomlConfigLoader::default();
|
||||
|
||||
cfg.set_inst_name(cli.instance_name.clone());
|
||||
|
||||
let hostname = gethostname::gethostname().to_string_lossy().to_string();
|
||||
let hostname = match cli.hostname {
|
||||
Some(name) => {
|
||||
// when allowing custom hostname, there may be empty
|
||||
if name.is_empty() {
|
||||
hostname
|
||||
} else {
|
||||
name
|
||||
}
|
||||
}
|
||||
None => hostname,
|
||||
};
|
||||
let re = regex::Regex::new(r"[^\u4E00-\u9FA5a-zA-Z0-9\-]*").unwrap();
|
||||
let mut hostname = re.replace_all(&hostname, "").to_string();
|
||||
if hostname.len() > 32 {
|
||||
hostname = hostname.chars().take(32).collect::<String>();
|
||||
}
|
||||
cfg.set_hostname(Some(hostname));
|
||||
|
||||
cfg.set_network_identity(NetworkIdentity::new(
|
||||
cli.network_name.clone(),
|
||||
cli.network_secret.clone(),
|
||||
|
||||
Reference in New Issue
Block a user