diff --git a/src/main.rs b/src/main.rs index f9bfa8d..faf153a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,7 @@ +use std::ffi::OsStr; use std::io::{self, IsTerminal}; -use std::path::Path; +use std::iter; +use std::path::{Path, PathBuf}; use std::process::ExitCode; use std::{error::Error as StdError, sync::Arc}; @@ -20,11 +22,17 @@ fn main_wrapped() -> Result<(), Box> { success.expect("logic error in CLI_ENABLE_COLOR"); } - // FIXME: handle relative paths without leading ./ let filepath = Path::new(&args.file); + let filepath: PathBuf = if filepath.is_relative() && !filepath.starts_with("./") { + iter::once(OsStr::new("./")) + .chain(filepath.iter()) + .collect() + } else { + filepath.to_path_buf() + }; // Get what file that thing is defined in. - let def_path = append_override::get_where(&args.name, filepath)?; + let def_path = append_override::get_where(&args.name, &filepath)?; let def_path = Arc::from(def_path); let mut opts = File::options(); opts.read(true)