From 26bdf7156e66e2c213cb3650a2cd40f304115478 Mon Sep 17 00:00:00 2001 From: "Azat S." Date: Thu, 24 Oct 2024 00:08:20 +0300 Subject: [PATCH] feat: add output directory option --- readme.md | 16 ++++++++++++++-- src/main.rs | 17 +++++++++++------ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/readme.md b/readme.md index ce986bf..78e778d 100644 --- a/readme.md +++ b/readme.md @@ -21,7 +21,9 @@ [![Version](https://img.shields.io/npm/v/todoctor.svg?color=2c7f50&labelColor=353c3c)](https://npmjs.com/package/todoctor) [![GitHub License](https://img.shields.io/badge/license-MIT-232428.svg?color=2c7f50&labelColor=353c3c)](https://github.com/azat-io/todoctor/blob/main/license) -Todoctor is a powerful tool for analyzing, tracking, and visualizing technical debt in your codebase using Git. It collects and monitors `TODO`/`FIXME` comments in your code, allowing you to observe changes over time. +Todoctor is a powerful tool for analyzing, tracking, and visualizing technical debt in your codebase using Git. + +It collects and monitors `TODO`/`FIXME` comments in your code, allowing you to observe changes over time. ## Why @@ -136,7 +138,7 @@ todoctor --months 6 ### --ignore -Allows you to specify files or directories to ignore during the analysis. This option can be used multiple times. +Allows you to specify files or directories to ignore during the analysis. The files in your `.gitignore` are ignored by default, you don't need to ignore them additionally. This option can be used multiple times. Example: @@ -187,6 +189,16 @@ Example: todoctor --exclude-keywords WARNING --exclude-keywords DEPRECATED ``` +### --output + +You can define the folder where the report file will be saved. By default it is `todoctor` folder in the project root. + +Example: + +```sh +todoctor --output report +``` + ### --help Displays this help message with available options. diff --git a/src/main.rs b/src/main.rs index 2fba346..035dbcd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,7 +30,6 @@ use todoctor::types::{TodoData, TodoHistory, TodoWithBlame}; use tokio::fs; use tokio::sync::Semaphore; -const TODOCTOR_DIR: &str = "todoctor"; const HISTORY_TEMP_FILE: &str = "todo_history_temp.json"; #[derive(Parser, Debug)] @@ -57,6 +56,10 @@ struct Cli { /// Keywords to exclude from tracking (can be used multiple times) #[arg(short = 'E', long, action = ArgAction::Append)] exclude_keywords: Vec, + + /// Output directory + #[arg(short, long, default_value = "todoctor")] + output: String, } #[tokio::main] @@ -87,6 +90,8 @@ async fn main() { .map(|values| values.map(String::from).collect()) .unwrap_or_else(Vec::new); + let output_directory = args.get_one::("output").unwrap(); + if !check_git_repository(".").await { eprintln!("Error: This is not a Git repository."); process::exit(1); @@ -313,12 +318,12 @@ async fn main() { writer.flush().expect("Failed to flush writer"); - if fs::metadata(TODOCTOR_DIR).await.is_ok() { - fs::remove_dir_all(TODOCTOR_DIR) + if fs::metadata(output_directory).await.is_ok() { + fs::remove_dir_all(output_directory) .await .expect("Error: Failed to remove directory"); } - fs::create_dir_all(TODOCTOR_DIR) + fs::create_dir_all(output_directory) .await .expect("Error creating directory"); @@ -358,11 +363,11 @@ async fn main() { let dist_path: PathBuf = get_dist_path().expect("Error: Could not get current dist path."); - copy_dir_recursive(&dist_path, Path::new(TODOCTOR_DIR)) + copy_dir_recursive(&dist_path, Path::new(output_directory)) .await .expect("Error copying directory"); - let index_path = Path::new(TODOCTOR_DIR).join("index.html"); + let index_path = Path::new(output_directory).join("index.html"); if fs::metadata(&index_path).await.is_ok() { let mut index_content = fs::read_to_string(&index_path) .await