diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/src/main.rs b/src/main.rs index c5240fc..27e19fe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,6 @@ )] #![allow(clippy::missing_docs_in_private_items)] -use std::env::current_dir; use std::fs::metadata; use std::io::stdin; use std::path::PathBuf; @@ -30,29 +29,25 @@ mod makefile; use args::Args; use makefile::{Makefile, MakefileReader}; +const DEFAULT_PATHS: &[&str] = &[ + #[cfg(feature = "full")] + "GNUmakefile", + "makefile", + "Makefile", +]; + fn main() -> Result<()> { jane_eyre::install()?; let mut args = Args::from_env_and_args(); // If no makefile is specified, try some options. if args.makefile.is_empty() { - args.makefile = vec![if metadata("./makefile").is_ok() { - "./makefile".into() - } else if metadata("./Makefile").is_ok() { - "./Makefile".into() - } else { - bail!( - "no makefile specified and neither {} nor {} was found.", - current_dir().map_or_else( - |_| "./makefile".to_owned(), - |path| path.join("makefile").display().to_string() - ), - current_dir().map_or_else( - |_| "./Makefile".to_owned(), - |path| path.join("Makefile").display().to_string() - ), - ); - }]; + let default_makefile = DEFAULT_PATHS.iter().find(|name| metadata(name).is_ok()); + let default_makefile = match default_makefile { + Some(x) => x, + None => bail!("no makefile found (tried {})", DEFAULT_PATHS.join(", ")), + }; + args.makefile = vec![default_makefile.into()]; } // Read in the makefile(s) specified. // TODO dump command-line args into MAKEFLAGS |