aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/args.rs4
-rw-r--r--src/main.rs4
2 files changed, 8 insertions, 0 deletions
diff --git a/src/args.rs b/src/args.rs
index 6a46986..9613dc3 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -116,6 +116,10 @@ pub struct Args {
#[structopt(short, long)]
pub touch: bool,
+ /// Change to the given directory before running.
+ #[structopt(short = "C", long, parse(from_os_str))]
+ pub directory: Option<PathBuf>,
+
/// Target names or macro definitions.
///
/// If no target is specified, while make is processing the makefiles, the first
diff --git a/src/main.rs b/src/main.rs
index f0e0c1d..b43249d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -20,6 +20,7 @@
clippy::todo
)]
+use std::env;
use std::fs::metadata;
use std::io::stdin;
use std::path::PathBuf;
@@ -44,6 +45,9 @@ fn main() -> Result<()> {
jane_eyre::install()?;
let mut args = Args::from_env_and_args();
+ if let Some(dir) = args.directory.as_ref() {
+ env::set_current_dir(dir)?;
+ }
// If no makefile is specified, try some options.
if args.makefile.is_empty() {
let default_makefile = DEFAULT_PATHS.iter().find(|name| metadata(name).is_ok());