Skip to content

Commit

Permalink
use target-dir
Browse files Browse the repository at this point in the history
  • Loading branch information
n01e0 committed Jan 18, 2024
1 parent 9700595 commit 76c9f21
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ppb"
version = "0.6.0"
version = "0.7.0"
edition = "2021"
authors = ["n01e0 <[email protected]>"]
license = "MIT"
Expand Down
5 changes: 4 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub struct ConfigFile {
pub title_format: Option<String>,
pub body_format: Option<String>,
pub ignore_file: Option<Vec<String>>,
pub target_dir: Option<String>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -124,7 +125,9 @@ impl Config {
.ignore_file
.or(args.ignore_file.clone())
.unwrap_or(vec![]),
target_dir: args.target_dir.clone(),
target_dir: config_file
.target_dir
.unwrap_or(args.target_dir.clone()),
})
}
None => Ok(Config {
Expand Down
9 changes: 6 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ async fn main() -> Result<()> {
let args = Args::parse();

if args.dry_run {
let (pattern, body_format, title_format) = match args.config {
let (target_dir, pattern, body_format, title_format) = match args.config {
Some(config) => {
let config: ConfigFile = serde_yaml::from_str(&std::fs::read_to_string(config)?)?;
(
config.target_dir.with_context(|| "dry_run needs target dir")?,
format!("({})", config.annotation_labels.with_context(|| "dry_run needs annotation labels")?.join("|")),
config.body_format.with_context(|| "dry_run needs body format")?,
config.title_format.with_context(|| "dry_run needs title format")?,
)
}
None => (
args.target_dir
.clone(),
format!(
"({})",
args.annotation_labels
Expand All @@ -36,7 +39,7 @@ async fn main() -> Result<()> {
.with_context(|| "dry_run needs title format")?,
),
};
let postpones = Postpone::search(&pattern, &args.ignore_file.unwrap_or(Vec::new()))?
let postpones = Postpone::search(&target_dir, &pattern, &args.ignore_file.unwrap_or(Vec::new()))?
.into_iter()
.map(|postpone| postpone.to_issue(&title_format, &body_format))
.filter_map(|issue| issue.ok())
Expand All @@ -59,7 +62,7 @@ async fn main() -> Result<()> {
.filter(|issue| issue.labels.iter().any(|label| label.name == "postpone"))
.collect::<Vec<_>>();

let postpones = Postpone::search(&pattern, &config.ignore_file)?
let postpones = Postpone::search(&config.target_dir, &pattern, &config.ignore_file)?
.into_iter()
.map(|postpone| postpone.to_issue(&config.title_format, &config.body_format))
.filter_map(|issue| issue.ok())
Expand Down
4 changes: 2 additions & 2 deletions src/postpone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ pub struct Postpone {
}

impl Postpone {
pub fn search(pattern: &str, ignore_file: &[String]) -> Result<Vec<Self>> {
pub fn search(target_dir: &str, pattern: &str, ignore_file: &[String]) -> Result<Vec<Self>> {
let matcher = RegexMatcher::new_line_matcher(pattern)?;
let mut result = Vec::new();

// TODO: layonとか使って並列化したい
Walk::new(".")
Walk::new(target_dir)
.filter_map(|e| e.ok())
.filter(|e| e.file_type().map(|t| t.is_file()).unwrap_or(false))
.filter(|e| !e.path().to_str().unwrap().starts_with(".git"))
Expand Down

0 comments on commit 76c9f21

Please sign in to comment.