Skip to content

Commit

Permalink
feat: add output directory option
Browse files Browse the repository at this point in the history
  • Loading branch information
azat-io committed Oct 23, 2024
1 parent 68027cb commit 26bdf71
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
16 changes: 14 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:

Expand Down Expand Up @@ -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.
Expand Down
17 changes: 11 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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<String>,

/// Output directory
#[arg(short, long, default_value = "todoctor")]
output: String,
}

#[tokio::main]
Expand Down Expand Up @@ -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::<String>("output").unwrap();

if !check_git_repository(".").await {
eprintln!("Error: This is not a Git repository.");
process::exit(1);
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 26bdf71

Please sign in to comment.