mirror of
https://github.com/2e3s/awatcher.git
synced 2025-06-07 12:05:49 +00:00
Use provided from cli config name
This commit is contained in:
parent
d5103bfe78
commit
04e20c1eb0
@ -62,7 +62,21 @@ struct FileConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FileConfig {
|
impl FileConfig {
|
||||||
fn new(config_path: &Path) -> Result<Self, BoxedError> {
|
fn new(matches: &ArgMatches) -> Result<Self, BoxedError> {
|
||||||
|
let mut config_path: PathBuf = dirs::config_dir().ok_or("Config directory is unknown")?;
|
||||||
|
config_path.push("awatcher");
|
||||||
|
config_path.push("config.toml");
|
||||||
|
if matches.contains_id("config") {
|
||||||
|
let config_file = matches.get_one::<String>("config");
|
||||||
|
if let Some(path) = config_file {
|
||||||
|
if let Err(e) = std::fs::metadata(path) {
|
||||||
|
warn!("Invalid config filename, using the default config: {e}");
|
||||||
|
} else {
|
||||||
|
config_path = Path::new(path).to_path_buf();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if config_path.exists() {
|
if config_path.exists() {
|
||||||
debug!("Reading config at {}", config_path.display());
|
debug!("Reading config at {}", config_path.display());
|
||||||
let config_content = std::fs::read_to_string(config_path)
|
let config_content = std::fs::read_to_string(config_path)
|
||||||
@ -72,14 +86,14 @@ impl FileConfig {
|
|||||||
} else {
|
} else {
|
||||||
let config = format!(
|
let config = format!(
|
||||||
r#"# The commented values are the defaults on the file creation
|
r#"# The commented values are the defaults on the file creation
|
||||||
[server]
|
[server]
|
||||||
# port = {}
|
# port = {}
|
||||||
# host = "{}"
|
# host = "{}"
|
||||||
[awatcher]
|
[awatcher]
|
||||||
# idle-timeout-seconds={}
|
# idle-timeout-seconds={}
|
||||||
# poll-time-idle-seconds={}
|
# poll-time-idle-seconds={}
|
||||||
# poll-time-window-seconds={}
|
# poll-time-window-seconds={}
|
||||||
"#,
|
"#,
|
||||||
default_port(),
|
default_port(),
|
||||||
default_host(),
|
default_host(),
|
||||||
default_idle_timeout_seconds(),
|
default_idle_timeout_seconds(),
|
||||||
@ -143,10 +157,6 @@ where
|
|||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn from_cli() -> Result<Self, BoxedError> {
|
pub fn from_cli() -> Result<Self, BoxedError> {
|
||||||
let mut config_path: PathBuf = dirs::config_dir().ok_or("Config directory is unknown")?;
|
|
||||||
config_path.push("awatcher");
|
|
||||||
config_path.push("config.toml");
|
|
||||||
|
|
||||||
let matches = Command::new("Activity Watcher")
|
let matches = Command::new("Activity Watcher")
|
||||||
.version("0.1.0")
|
.version("0.1.0")
|
||||||
.about("A set of ActivityWatch desktop watchers")
|
.about("A set of ActivityWatch desktop watchers")
|
||||||
@ -170,7 +180,7 @@ impl Config {
|
|||||||
])
|
])
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
let mut config = FileConfig::new(config_path.as_path())?;
|
let mut config = FileConfig::new(&matches)?;
|
||||||
config.merge_cli(&matches);
|
config.merge_cli(&matches);
|
||||||
|
|
||||||
let hostname = gethostname::gethostname().into_string().unwrap();
|
let hostname = gethostname::gethostname().into_string().unwrap();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user