mirror of
https://github.com/pcvolkmer/checkbar.git
synced 2025-04-19 19:16:50 +00:00
Add optional config file argument
This commit is contained in:
parent
a893d7a6f0
commit
16b68bdaca
@ -33,6 +33,12 @@ You can optionally specify `check_type`:
|
||||
* `Html`: Default value, checks if a request is succeessful and returns HTTP OK - 200.
|
||||
* `Actuator`: Like `Html`, but checks if _Actuator_ shows that the application is up and running.
|
||||
|
||||
To use more than one configuration, pass the config file location as first argument to the application.
|
||||
|
||||
----
|
||||
$ checkbar /etc/checkbar_example.toml
|
||||
----
|
||||
|
||||
=== Colors
|
||||
|
||||
To change the colors, use the following configuration. As an example the colors of the default configuration are shown.
|
||||
|
14
src/main.rs
14
src/main.rs
@ -1,5 +1,6 @@
|
||||
use serde::Deserialize;
|
||||
use std::fmt::{Display, Formatter, Result};
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::process;
|
||||
use std::time::Duration;
|
||||
@ -122,12 +123,15 @@ async fn print_states(check_configs: &[CheckConfig]) {
|
||||
println!("{}],", entries.join(","));
|
||||
}
|
||||
|
||||
fn get_config_file() -> String {
|
||||
match env::args().nth(1) {
|
||||
Some(config_file) => config_file,
|
||||
None => format!("{}/.checkbar.toml", dirs::home_dir().unwrap().to_str().unwrap_or(""))
|
||||
}
|
||||
}
|
||||
|
||||
fn get_config() -> Config {
|
||||
let home_dir = dirs::home_dir().unwrap();
|
||||
match fs::read_to_string(format!(
|
||||
"{}/.checkbar.toml",
|
||||
home_dir.to_str().unwrap_or("")
|
||||
)) {
|
||||
match fs::read_to_string(get_config_file()) {
|
||||
Ok(config) => match toml::from_str(config.as_str()) {
|
||||
Ok(config) => config,
|
||||
Err(_e) => Config {
|
||||
|
Loading…
x
Reference in New Issue
Block a user