diff options
author | Ryan Leckey <ryan@launchbadge.com> | 2017-06-22 17:10:47 -0700 |
---|---|---|
committer | Ryan Leckey <ryan@launchbadge.com> | 2017-06-22 17:10:47 -0700 |
commit | 6bfaf90fdf67197c511a7594b37d835e964edccd (patch) | |
tree | aedca78e59887c30bd2e34626b06f24f29de0d81 /src/file/source | |
parent | 159bb52c595384fed44a2c669198d50f2a758a9a (diff) |
Implement Source for Vec<T: Source> and From<Path> for File
Diffstat (limited to 'src/file/source')
-rw-r--r-- | src/file/source/file.rs | 28 |
1 files changed, 6 insertions, 22 deletions
diff --git a/src/file/source/file.rs b/src/file/source/file.rs index 426c0b5..790933f 100644 --- a/src/file/source/file.rs +++ b/src/file/source/file.rs @@ -15,36 +15,20 @@ use super::{FileFormat, FileSource}; /// Describes a file sourced from a file #[derive(Clone, Debug)] pub struct FileSourceFile { - /// Basename of configuration file - name: String, - - /// Directory where configuration file is found - /// When not specified, the current working directory (CWD) is considered - path: Option<String>, + /// Path of configuration file + name: PathBuf, } impl FileSourceFile { - pub fn new(name: &str) -> FileSourceFile { - FileSourceFile { - name: name.into(), - path: None, - } + pub fn new(name: PathBuf) -> FileSourceFile { + FileSourceFile { name: name } } fn find_file(&self, format_hint: Option<FileFormat>) -> Result<(PathBuf, FileFormat), Box<Error>> { - // Build expected configuration file - let mut basename = PathBuf::new(); - - if let Some(ref path) = self.path { - basename.push(path.clone()); - } - - basename.push(self.name.clone()); - // First check for an _exact_ match - let mut filename = env::current_dir()?.as_path().join(basename.clone()); + let mut filename = env::current_dir()?.as_path().join(self.name.clone()); if filename.is_file() { return match format_hint { Some(format) => Ok((filename, format)), @@ -92,7 +76,7 @@ impl FileSourceFile { Err(Box::new(io::Error::new(io::ErrorKind::NotFound, format!("configuration file \"{}\" not found", - basename.to_string_lossy())))) + self.name.to_string_lossy())))) } } |