fix: address todos not showing relative dirs
This commit is contained in:
@@ -7,4 +7,5 @@ edition = "2018"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
colored = "2.0.0"
|
colored = "2.0.0"
|
||||||
gitignore = "1.0.7"
|
gitignore = "1.0.7"
|
||||||
|
path-absolutize = "3.0.10"
|
||||||
40
src/main.rs
40
src/main.rs
@@ -2,6 +2,7 @@ use std::fs;
|
|||||||
use std::env;
|
use std::env;
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use gitignore;
|
use gitignore;
|
||||||
|
use path_absolutize::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = env::args().collect();
|
||||||
@@ -32,22 +33,24 @@ fn main() {
|
|||||||
|
|
||||||
if gi_exists {
|
if gi_exists {
|
||||||
let gi_str = args[1].to_owned() + "/.gitignore";
|
let gi_str = args[1].to_owned() + "/.gitignore";
|
||||||
let gi_path = std::path::Path::new(&gi_str);
|
let _p = std::path::Path::new(&gi_str).absolutize().unwrap();
|
||||||
|
let gi_str_abs = _p.to_str().unwrap();
|
||||||
|
let gi_path = std::path::Path::new(&gi_str_abs);
|
||||||
let gi= gitignore::File::new(gi_path).unwrap();
|
let gi= gitignore::File::new(gi_path).unwrap();
|
||||||
traverse_dir(&args[1], &mut todos, Some(&gi)).unwrap();
|
iterate_included_files(&mut todos, &gi).unwrap();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
traverse_dir(&args[1], &mut todos, None).unwrap();
|
traverse_dir(&args[1], &mut todos).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO eventually add option to export to file
|
// TODO eventually add option to export to file
|
||||||
println!("{:4} {:05} {:15} {:50}", "", "Line".bold(), "File".bold(), "Comment".bold());
|
println!("{:4} {:05} {:20} {:50}", "", "LINE".bold(), "FILE".bold(), "COMMENT".bold());
|
||||||
for todo in todos {
|
for todo in todos {
|
||||||
println!("{:4} {:05} {:15} {:50}", "TODO", todo.line_number.to_string().yellow(), todo.file_name.green(), todo.comment);
|
println!("{:4} {:05} {:20} {:50}", "TODO".bold(), todo.line_number.to_string().yellow(), todo.file_name.green(), todo.comment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn traverse_dir(path: &str, todos: &mut Vec<Todo>, gi_option: Option<&gitignore::File>) -> Result<(), std::io::Error> {
|
fn traverse_dir(path: &str, todos: &mut Vec<Todo>) -> Result<(), std::io::Error> {
|
||||||
let objects = fs::read_dir(path.to_owned())?;
|
let objects = fs::read_dir(path.to_owned())?;
|
||||||
|
|
||||||
for result in objects {
|
for result in objects {
|
||||||
@@ -55,18 +58,10 @@ fn traverse_dir(path: &str, todos: &mut Vec<Todo>, gi_option: Option<&gitignore:
|
|||||||
let obj_str = obj_path.to_str().unwrap();
|
let obj_str = obj_path.to_str().unwrap();
|
||||||
let obj_metadata = fs::metadata(obj_str)?;
|
let obj_metadata = fs::metadata(obj_str)?;
|
||||||
|
|
||||||
let is_excluded = match gi_option {
|
if obj_metadata.is_dir() {
|
||||||
Some(gi) => {
|
traverse_dir(obj_str, todos)?;
|
||||||
let dir_path = std::path::Path::new(obj_str);
|
|
||||||
gi.is_excluded(dir_path).unwrap()
|
|
||||||
}
|
|
||||||
None => { false }
|
|
||||||
};
|
|
||||||
|
|
||||||
if !is_excluded && obj_metadata.is_dir() {
|
|
||||||
traverse_dir(obj_str, todos, gi_option)?;
|
|
||||||
}
|
}
|
||||||
else if !is_excluded && obj_metadata.is_file() && obj_str.ends_with(".py") {
|
else if obj_metadata.is_file() && obj_str.ends_with(".py") { // TODO support other files besides .py
|
||||||
get_todos(obj_str, todos)?;
|
get_todos(obj_str, todos)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -74,6 +69,17 @@ fn traverse_dir(path: &str, todos: &mut Vec<Todo>, gi_option: Option<&gitignore:
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn iterate_included_files(todos: &mut Vec<Todo>, gi: &gitignore::File) -> Result<(), std::io::Error> {
|
||||||
|
for file_path in gi.included_files().unwrap() {
|
||||||
|
let file_str = file_path.to_str().unwrap();
|
||||||
|
if file_str.ends_with(".py") { // TODO support other files besides .py
|
||||||
|
get_todos(file_str, todos)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn get_todos(path: &str, todos: &mut Vec<Todo>) -> Result<(), std::io::Error> {
|
fn get_todos(path: &str, todos: &mut Vec<Todo>) -> Result<(), std::io::Error> {
|
||||||
let contents = fs::read_to_string(path)?;
|
let contents = fs::read_to_string(path)?;
|
||||||
let mut line_number = 0;
|
let mut line_number = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user