Skip to content

Commit

Permalink
feat: add ignore cli argument
Browse files Browse the repository at this point in the history
  • Loading branch information
azat-io committed Oct 19, 2024
1 parent edf5b95 commit 6e6aac0
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"words": [
"azat",
"browserslistrc",
"canonicalize",
"chartjs",
"chrono",
"combak",
Expand Down
10 changes: 10 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ Example:
todoctor --months 6
```

### --ignore

Allows you to specify files or directories to ignore during the analysis. This option can be used multiple times.

Example:

```sh
todoctor --ignore src/deprecated/ --ignore tests/legacy.test.js
```

### --help

Displays this help message with available options.
Expand Down
16 changes: 16 additions & 0 deletions src/identify_not_ignored_file.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use std::path::Path;

pub fn identify_not_ignored_file(file: &str, ignores: &[String]) -> bool {
let file_path = Path::new(file)
.canonicalize()
.unwrap_or_else(|_| Path::new(file).to_path_buf());

let is_ignored = ignores.iter().any(|ignored| {
let ignored_path = Path::new(ignored)
.canonicalize()
.unwrap_or_else(|_| Path::new(ignored).to_path_buf());
file_path.starts_with(&ignored_path)
});

!is_ignored
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod get_history;
pub mod get_line_from_position;
pub mod get_project_name;
pub mod get_todoctor_version;
pub mod identify_not_ignored_file;
pub mod identify_supported_file;
pub mod identify_todo_comment;
pub mod prepare_blame_data;
Expand Down
21 changes: 18 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::{CommandFactory, Parser};
use clap::{ArgAction, CommandFactory, Parser};
use futures::future::join_all;
use indicatif::{ProgressBar, ProgressStyle};
use open;
Expand All @@ -21,6 +21,7 @@ use todoctor::get_history::get_history;
use todoctor::get_line_from_position::get_line_from_position;
use todoctor::get_project_name::get_project_name;
use todoctor::get_todoctor_version::get_todoctor_version;
use todoctor::identify_not_ignored_file::identify_not_ignored_file;
use todoctor::identify_supported_file::identify_supported_file;
use todoctor::identify_todo_comment::identify_todo_comment;
use todoctor::prepare_blame_data::{prepare_blame_data, PreparedBlameData};
Expand All @@ -39,6 +40,10 @@ struct Cli {
/// Number of months to process
#[arg(short, long, default_value_t = 3, value_parser = clap::value_parser!(u32).range(1..))]
month: u32,

/// Paths to ignore (can be used multiple times)
#[arg(short, long, action = ArgAction::Append)]
ignore: Vec<String>,
}

#[tokio::main]
Expand All @@ -54,6 +59,10 @@ async fn main() {
let args = Cli::command().version(version_static).get_matches();

let months = args.get_one::<u32>("month").unwrap();
let ignores: Vec<String> = args
.get_many::<String>("ignore")
.map(|values| values.map(String::from).collect())
.unwrap_or_else(Vec::new);

if !check_git_repository(".").await {
eprintln!("Error: This is not a Git repository.");
Expand All @@ -64,7 +73,10 @@ async fn main() {

let files: Vec<String> = files_list
.into_iter()
.filter(|file| identify_supported_file(file))
.filter(|file| {
identify_not_ignored_file(file, &ignores)
&& identify_supported_file(file)
})
.collect();

let todo_data_tasks: Vec<_> = files
Expand Down Expand Up @@ -180,7 +192,10 @@ async fn main() {

let supported_files: Vec<_> = files_list
.into_iter()
.filter(|file| identify_supported_file(file))
.filter(|file| {
identify_not_ignored_file(file, &ignores)
&& identify_supported_file(file)
})
.collect();

let file_tasks: Vec<_> = supported_files
Expand Down

0 comments on commit 6e6aac0

Please sign in to comment.