Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only search for config file when required #560

Merged
merged 2 commits into from
Aug 12, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use std::{path::PathBuf, sync::Arc};

use quilkin::Config;
use tracing::info;

const VERSION: &str = env!("CARGO_PKG_VERSION");
Expand Down Expand Up @@ -108,28 +109,16 @@ async fn main() -> quilkin::Result<()> {
.init();
}

let config = std::fs::File::open(&cli.config)
.or_else(|error| {
if cfg!(unix) {
std::fs::File::open("/etc/quilkin/quilkin.yaml")
} else {
Err(error)
}
})
.map_err(eyre::Error::from)
.and_then(|file| quilkin::Config::from_reader(file).map_err(From::from))
.unwrap();

info!(
version = &*version,
commit = quilkin::metadata::build::GIT_COMMIT_HASH,
"Starting Quilkin"
);

match cli.command {
Commands::Run => quilkin::run(config, vec![]).await,
Commands::Run => quilkin::run(read_config(&cli.config), vec![]).await,
Commands::Manage { provider } => {
let config = Arc::new(config);
let config = Arc::new(read_config(&cli.config));
let provider_task = match provider {
ProviderCommands::Agones {
gameservers_namespace,
Expand Down Expand Up @@ -190,3 +179,18 @@ async fn main() -> quilkin::Result<()> {
}
}
}

/// Searches for the configuration file, and panics if not found.
fn read_config(path: &PathBuf) -> Config {
std::fs::File::open(path)
.or_else(|error| {
if cfg!(unix) {
std::fs::File::open("/etc/quilkin/quilkin.yaml")
} else {
Err(error)
}
})
.map_err(eyre::Error::from)
.and_then(|file| quilkin::Config::from_reader(file).map_err(From::from))
.unwrap()
}