diff --git a/README.md b/README.md index 2d5e069..7e9ed81 100644 --- a/README.md +++ b/README.md @@ -195,14 +195,6 @@ There are no downloadable builds at the moment. To compile the tool manually: 2. `cargo install --git https://github.com/archtechx/todo-system.git` 3. The tool will be added to your `$PATH` automatically as `todos` -If you use Nix (with flakes), you can use this repo as an input. The tool is -exported as the default package. You can try it out using: -``` -nix run github:archtechx/todo-system -- --help -# or create a temporary shell with `todos` in PATH: -nix shell github:archtechx/todo-system -``` - I personally also like creating an alias that does `todos | less`: ```sh alias t="todos | less" diff --git a/src/main.rs b/src/main.rs index 5344371..8fea53d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ use std::path::PathBuf; use clap::{Parser, ArgAction}; use crate::entries::Entry; use crate::render::render_entries; -use crate::scan::{Stats, scan_dir, scan_todo_file, scan_readme_file, Exclude}; +use crate::scan::{Stats, scan_dir, scan_todo_file, scan_readme_file}; pub mod scan; pub mod render; @@ -43,7 +43,7 @@ fn main() { let root_dir: PathBuf = std::env::current_dir().unwrap(); let mut paths: Vec = vec![]; - let mut excludes: Vec = vec![]; + let mut excludes: Vec = vec![]; let mut entries: Vec = vec![]; let mut stats = Stats::new(args.verbose); @@ -68,7 +68,7 @@ fn main() { if path.exists() { if let Ok(realpath) = canonicalize(path) { - excludes.push(Exclude::Path(realpath)); + excludes.push(realpath); } } } @@ -80,13 +80,13 @@ fn main() { readme_path.push(&args.readme); if todos_path.exists() { - excludes.push(Exclude::Path(todos_path.clone())); + excludes.push(todos_path.clone()); scan_todo_file(&todos_path, &mut entries).unwrap(); } if readme_path.exists() { - excludes.push(Exclude::Path(readme_path.clone())); + excludes.push(readme_path.clone()); scan_readme_file(&readme_path, &mut entries).unwrap(); } diff --git a/src/render.rs b/src/render.rs index 5e89c6b..d8a5db5 100644 --- a/src/render.rs +++ b/src/render.rs @@ -113,14 +113,13 @@ pub fn render_entries(entries: Vec) { println!(); } - if generic_entries.len() > 0 { - write_ansi(&mut stdout, Color::White, "## Other", true); - writeln!(stdout).unwrap(); + write_ansi(&mut stdout, Color::White, "## Other", true); + writeln!(stdout).unwrap(); - generic_entries.sort_by(|a, b| a.text.partial_cmp(&b.text).unwrap()); + generic_entries.sort_by(|a, b| a.text.partial_cmp(&b.text).unwrap()); - for item in generic_entries { - item.render(); - } + for item in generic_entries { + item.render(); } + } diff --git a/src/scan.rs b/src/scan.rs index 0280771..6d6e8fb 100644 --- a/src/scan.rs +++ b/src/scan.rs @@ -1,27 +1,12 @@ use std::io; use std::fs::{self, canonicalize}; use std::path::{Path, PathBuf}; -use glob::{Pattern}; +use glob::glob; const PRIORITY_CHARS: [char; 10] = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; use crate::entries::{Entry, EntryData, Location}; -#[derive(Debug, PartialEq, Eq)] -pub enum Exclude { - Path(PathBuf), - Glob(Pattern), -} - -impl Exclude { - pub fn matches(&self, path: &Path) -> bool { - match self { - Exclude::Path(p) => p == path, - Exclude::Glob(g) => g.matches_path(path), - } - } -} - pub struct Stats { visited_folder_count: usize, visited_file_count: usize, @@ -115,7 +100,7 @@ fn clean_line<'a>(line: &'a str, delimiter_word: &str) -> &'a str { .trim() } -pub fn add_excludes_from_gitignore(base_dir: &PathBuf, excludes: &mut Vec) { +pub fn add_excludes_from_gitignore(base_dir: &PathBuf, excludes: &mut Vec) { let mut gitignore = base_dir.clone(); gitignore.push(".gitignore"); @@ -130,7 +115,7 @@ pub fn add_excludes_from_gitignore(base_dir: &PathBuf, excludes: &mut Vec) -> io::Result<()> { Ok(()) } -pub fn scan_dir(dir: &Path, entries: &mut Vec, excludes: &mut Vec, stats: &mut Stats) -> io::Result<()> { +pub fn scan_dir(dir: &Path, entries: &mut Vec, excludes: &mut Vec, stats: &mut Stats) -> io::Result<()> { let mut gitignore = dir.to_path_buf().clone(); gitignore.push(".gitignore"); @@ -251,11 +234,11 @@ pub fn scan_dir(dir: &Path, entries: &mut Vec, excludes: &mut Vec, excludes: &mut Vec