Add persistent network identification

This commit is contained in:
Age Manning
2019-07-01 16:38:42 +10:00
parent 7dc5e2f959
commit af28d5e20c
12 changed files with 220 additions and 71 deletions

View File

@@ -1,6 +1,5 @@
use clap::ArgMatches;
use serde_derive::{Deserialize, Serialize};
use std::fs;
use std::fs::File;
use std::io::prelude::*;
use std::path::PathBuf;
@@ -105,15 +104,3 @@ where
Ok(None)
}
}
pub fn get_data_dir(args: &ArgMatches, default_data_dir: PathBuf) -> Result<PathBuf, &'static str> {
if let Some(data_dir) = args.value_of("data_dir") {
Ok(PathBuf::from(data_dir))
} else {
let path = dirs::home_dir()
.ok_or_else(|| "Unable to locate home directory")?
.join(&default_data_dir);
fs::create_dir_all(&path).map_err(|_| "Unable to create data_dir")?;
Ok(path)
}
}