diff --git a/git-cliff/src/args.rs b/git-cliff/src/args.rs index 427c9d58a1..c617b9d7a4 100644 --- a/git-cliff/src/args.rs +++ b/git-cliff/src/args.rs @@ -28,7 +28,10 @@ pub struct Opt { value_name = "PATH", default_value = "cliff.toml" )] - pub config: String, + pub config: PathBuf, + /// Sets the working directory. + #[structopt(short, long, env, value_name = "PATH")] + pub workdir: Option, /// Sets the repository to parse commits from. #[structopt(short, long, env, value_name = "PATH")] pub repository: Option, diff --git a/git-cliff/src/lib.rs b/git-cliff/src/lib.rs index 1fea33da23..e6d4ad7b79 100644 --- a/git-cliff/src/lib.rs +++ b/git-cliff/src/lib.rs @@ -24,9 +24,27 @@ use std::fs::{ use std::io; /// Runs `git-cliff`. -pub fn run(args: Opt) -> Result<()> { +pub fn run(mut args: Opt) -> Result<()> { + // Set the working directory. + if let Some(workdir) = args.workdir { + args.config = workdir.join(args.config); + args.repository = match args.repository { + Some(repository) => Some(workdir.join(repository)), + None => Some(workdir.clone()), + }; + if let Some(changelog) = args.changelog { + args.changelog = Some(workdir.join(changelog)); + } + } + // Parse configuration file. - let mut config = Config::parse(args.config)?; + let mut config = Config::parse(match args.config.to_str() { + Some(v) => Ok(v.to_string()), + None => Err(Error::IoError(io::Error::new( + io::ErrorKind::Other, + "path contains invalid characters", + ))), + }?)?; // Update the configuration based on command line arguments. match args.strip.as_deref() {