Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for -d #16

Merged
merged 1 commit into from
Aug 29, 2024
Merged

feat: add support for -d #16

merged 1 commit into from
Aug 29, 2024

Conversation

ByteBaker
Copy link
Contributor

@ByteBaker ByteBaker commented Aug 24, 2024

Closes #8

  • only list directories by using -d flag

@ByteBaker ByteBaker changed the title feat: add support for -d feat: add support for -d #8 Aug 24, 2024
@ByteBaker ByteBaker changed the title feat: add support for -d #8 feat: add support for -d Aug 24, 2024
@ByteBaker
Copy link
Contributor Author

Hi @sighol, please review this and let me know how it is. I'll write code for -I in the next week perhaps.

@sighol
Copy link
Owner

sighol commented Aug 26, 2024

It looks like this PR broke the tests.
The tests in this projects really needs some refactoring, because it is a bit annoying to run them right now.
You first need to build with release mode, and then run cargo test.
It looks like something around the is_last calculation is wrong.

This used to be the output of cargo run -- tests,

├── compare
├── simple
│   └── yyy
│       ├── k
│       ├── s
│       │   ├── a
│       │   └── t
│       ├── test.txt
│       └── zz
│           └── a
│               └── b
│                   └── c
└── timer.py

7 directories, 6 files

And now it returns

tests
└── compare
├── simple
│   └── yyy
│       └── k
│       └── s
│           └── a
│           ├── t
│       ├── test.txt
│       ├── zz
│       │   └── a
│       │       └── b
│       │           └── c
├── timer.py

7 directories, 6 files

And thank you for making this PR! I am motivated to refactor the tests now, and maybe add some github actions.

@ByteBaker
Copy link
Contributor Author

ByteBaker commented Aug 26, 2024

My bad. Yes, I didn't run the tests, at all! Lemme go back and see what's up with this.

And yes, they do need refactoring. In fact the whole project. Personally, I think we should open an issue to track the roadmap around the following tasks (not in the same order). Please feel free to add or remove some.

  • Refactor the project structure, debloat main.rs.
  • Add documentation to track features ported from tree and the ones for future.
  • Add support for -I flag.
  • Add more test cases and refactor existing ones.
  • Benchmark the code and improve. Currently tree-rs seems to be slower than tree.
  • Work on issue Doesn't with symlinked directory on Windows #14

What do you think?

@sighol
Copy link
Owner

sighol commented Aug 26, 2024

Since we talked about doing some refactorings, I pushed some changes that I think improved the structure somewhat.
#17

It unfortunately broke your PR, but that should hopefully be easy to resolve.

@sighol
Copy link
Owner

sighol commented Aug 26, 2024

Found the error. This patch should fix it up.

diff --git a/src/pathiterator.rs b/src/pathiterator.rs
index 40f1059..72bb7f4 100644
--- a/src/pathiterator.rs
+++ b/src/pathiterator.rs
@@ -102,16 +100,12 @@ impl FileIterator {
                 )
             });
 
-        for entry in entries {
-            let item = IteratorItem::new(&entry.path(), item.level + 1, false);
+        for (index, entry) in entries.iter().enumerate() {
+            let item = IteratorItem::new(&entry.path(), item.level + 1, index == 0);
             if self.is_included(&item.file_name, item.is_dir()) {
                 self.queue.push_back(item);
             }
         }
-
-        if let Some(item) = self.queue.back_mut() {
-            item.is_last = true;
-        }
     }
 }

The queue is kept for multiple iterations, so it can contain folders on different levels. Setting is_last must be set based on the entries, not on the queue.

- only list directories by using `-d` flag
@ByteBaker
Copy link
Contributor Author

Hi @sighol, got a little occupied during the weekend and couldn't work on this one.

But hey, thanks a ton for the carry with the patch. I've made the change and pushed it here. See if it looks good to you.
I'm also gonna create the tracker issue as discussed earlier.

@sighol sighol merged commit 103fed6 into sighol:master Aug 29, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Option to ignore directories
2 participants