Skip to content

Commit

Permalink
feat(args): add --workdir argument
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun committed Jun 15, 2021
1 parent c056196 commit de439be
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
5 changes: 4 additions & 1 deletion git-cliff/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>,
/// Sets the repository to parse commits from.
#[structopt(short, long, env, value_name = "PATH")]
pub repository: Option<PathBuf>,
Expand Down
22 changes: 20 additions & 2 deletions git-cliff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit de439be

Please sign in to comment.