Skip to content
Snippets Groups Projects
Verified Commit 4dda4957 authored by Eduardo Trujillo's avatar Eduardo Trujillo
Browse files

refactor(config): Remove unused functions

parent 2d4752c8
No related branches found
No related tags found
1 merge request!3v2.0.0
......@@ -273,71 +273,19 @@ impl From<IndexStrategyConfig> for IndexStrategy {
}
}
/// Attempts to read a Config object from the specified path.
///
/// The configuration file is expected to be a TOML file.
pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Config> {
let path = path.as_ref();
log::info!("Reading config file from {}", path.display());
let contents = fs::read_to_string(path).context(OpenConfig { path })?;
let config = toml::from_str(&contents);
config.context(DeserializeConfig { path })
}
/// Attempts to read a Config object from the specified paths.
pub fn from_paths<P: AsRef<Path>>(paths: Vec<P>) -> Result<Config> {
for path in paths {
if path.as_ref().exists() {
return from_file(path);
}
}
Err(Error::NoValidPath)
}
/// Attempts to read a Config object from the current directory.
///
/// The configuration file is expected to be a TOML file named `config.toml`.
pub fn from_current_dir() -> Result<Config> {
let mut current_path = env::current_dir().context(GetCurrentDir)?;
current_path.push("config.toml");
from_file(&current_path)
}
/// Similar to `from_paths`. Uses a default set of paths:
///
/// - `CURRENT_WORKING_DIRECTORY/config.toml`
/// - `/etc/CRATE/config.toml`
pub fn from_default_paths() -> Result<Config> {
let mut current_path = env::current_dir().context(GetCurrentDir)?;
current_path.push("config.toml");
let mut config_path = PathBuf::from("/etc/");
config_path.push(PKG_NAME);
config_path.push("config.toml");
let paths = vec![current_path, config_path];
from_paths(paths)
}
#[cfg(test)]
mod tests {
use super::{from_file, BundleConfig, Config, ServerConfig, StatsConfig, UnbundlerConfig};
use collective::config::from_file;
use super::{BundleConfig, Config, ServerConfig, StatsConfig, UnbundlerConfig};
use std::path::{Path, PathBuf};
#[test]
fn test_from_file() {
let config: Config = from_file(&Path::new("config.sample.toml"), None).unwrap();
assert_eq!(
from_file(&Path::new("config.sample.toml")).unwrap(),
config,
Config {
stats: Some(StatsConfig {
address: "127.0.0.1:8089".parse().unwrap(),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment