fix: config file completion completing files

This commit is contained in:
Jan Christian Grünhage 2022-04-03 01:49:46 +02:00
parent 83d8cd2d54
commit 6a79d5adf1
2 changed files with 5 additions and 2 deletions

View file

@ -1,9 +1,12 @@
use clap::ValueHint;
#[derive(clap::Parser)] #[derive(clap::Parser)]
#[clap(author, version)] #[clap(author, version)]
/// Pings configured hosts in a configurable intervals and exposes metrics for prometheus. /// Pings configured hosts in a configurable intervals and exposes metrics for prometheus.
pub struct Cli { pub struct Cli {
/// Set config file /// Set config file
pub config: String, #[clap(value_hint = ValueHint::FilePath)]
pub config: std::path::PathBuf,
#[clap(short, long, parse(from_occurrences))] #[clap(short, long, parse(from_occurrences))]
/// Be verbose (you can add this up to 4 times for more logs). /// Be verbose (you can add this up to 4 times for more logs).
/// By default, only errors are logged, so no output is a good thing. /// By default, only errors are logged, so no output is a good thing.

View file

@ -103,7 +103,7 @@ fn setup_fern(level: log::LevelFilter) {
} }
} }
fn read_config(path: &str) -> Result<Config> { fn read_config(path: &std::path::Path) -> Result<Config> {
let config_file_content = std::fs::read_to_string(path).context("Couldn't read config file")?; let config_file_content = std::fs::read_to_string(path).context("Couldn't read config file")?;
toml::from_str(&config_file_content).context("Couldn't parse config file") toml::from_str(&config_file_content).context("Couldn't parse config file")
} }