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

Add --recursive option #43

Merged
merged 5 commits into from
Feb 13, 2023
Merged

Add --recursive option #43

merged 5 commits into from
Feb 13, 2023

Conversation

DerZade
Copy link
Contributor

@DerZade DerZade commented Feb 12, 2023

Add --recursive option and therefore fix #42.


This PR includes two breaking changes to the public API:

  • added second parameter (recurse) to spreet::fs::get_svg_input_paths
  • added second parameter (base_path) to spreet::sprite::sprite_name

I hope this is acceptable. If not, just let me know and I will add other functions instead of extending the existing ones. But this will result in some duplicate code 🙈

Copy link
Owner

@flother flother left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, I appreciate you taking the time to add this in. I have a few comments on minor things I'd like to see, but I'll be happy to merge this.

Other than the comments below, could you add a line to CHANGELOG.md to summarise the new flag?

README.md Outdated
@@ -99,6 +99,7 @@ Options:
-r, --ratio <RATIO> Set the output pixel ratio [default: 1]
--retina Set the pixel ratio to 2 (equivalent to `--ratio=2`)
--unique Store only unique images in the spritesheet, and map them to multiple names
--recursive Include images from subdirectories
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
--recursive Include images from subdirectories
--recursive Include images in sub-directories

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 7a6a857

src/fs.rs Outdated
/// (files whose names begin with `.`) but it does follow symlinks.
pub fn get_svg_input_paths(path: &Path) -> Vec<PathBuf> {
/// It ignores hidden files (files whose names begin with `.`) but it does follow symlinks.
pub fn get_svg_input_paths(path: &Path, recurse: bool) -> Vec<PathBuf> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's give this the same name as the command-line argument, for consistency.

Suggested change
pub fn get_svg_input_paths(path: &Path, recurse: bool) -> Vec<PathBuf> {
pub fn get_svg_input_paths(path: &Path, recursive: bool) -> Vec<PathBuf> {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 7a6a857

src/fs.rs Outdated
Comment on lines 42 to 43
if recurse && path_buf.is_dir() {
return Some(get_svg_input_paths(&path_buf.as_path(), recurse));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need the borrow, it'll be dereferenced by the compiler

Suggested change
if recurse && path_buf.is_dir() {
return Some(get_svg_input_paths(&path_buf.as_path(), recurse));
if recursive && path_buf.is_dir() {
return Some(get_svg_input_paths(path_buf.as_path(), recursive));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 7a6a857

src/fs.rs Outdated
if recurse && path_buf.is_dir() {
return Some(get_svg_input_paths(&path_buf.as_path(), recurse));
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Let's tighten up the whitespace

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 7a6a857

src/fs.rs Outdated
if is_useful_input(&entry) {
return Some(vec![path_buf]);
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 7a6a857

@@ -228,8 +228,18 @@ impl Spritesheet {
}

/// Returns the name (unique id within a spritesheet) taken from a file.
pub fn sprite_name(path: &Path) -> String {
format!("{}", path.file_stem().unwrap().to_string_lossy())
pub fn sprite_name(path: &Path, base_path: &Path) -> String {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it's doing something a little more complicated, I think this function's a perfect candidate for a unit test or two (I'm holding you to a higher standard than I hold myself, sorry!) Do you fancy adding some? One for when base_path has no impact, one when it does

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 73fda65

@@ -228,8 +228,18 @@ impl Spritesheet {
}

/// Returns the name (unique id within a spritesheet) taken from a file.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add an explanation of what base_path is used for

Suggested change
/// Returns the name (unique id within a spritesheet) taken from a file.
/// Returns the name (unique id within a spritesheet) taken from a file.
///
/// If `base_path` is given, it's used as prefix in the sprite name (minus any parents
/// shared with `path`).

Copy link
Contributor Author

@DerZade DerZade Feb 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 7a6a857

You're explanation starts with "If base_path is given". There is not really a choice tho 😂 so I adjusted it a bit. Is that okay?

@DerZade
Copy link
Contributor Author

DerZade commented Feb 13, 2023

Thank you for being so quick with the review :)

I have addressed most of your comments and have added a line to the change log. I have not mentioned any breaking changes to the API because there is no mention of something similar so far. Is that ok, or should I include it in the changelog as well?

The only thing left to do is #43 (comment), which I hope to get to tonight :) Done :)

@DerZade DerZade requested a review from flother February 13, 2023 12:05
Copy link
Owner

@flother flother left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic! Everything you've done looks good, thanks for responding so quickly.

I realised that cargo fmt/check/clippy run on master but not on PRs (I need to configure the CI workflow properly), so I just ran them now and there's one last change that needs to be made. Sorry I didn't pick this up before, but it's a small change. Clippy's complaining that get_svg_input_paths currently has a needless return. It's an easy fix though, and then we're good to merge.

src/fs.rs Outdated
Comment on lines 41 to 48

if recursive && path_buf.is_dir() {
return Some(get_svg_input_paths(path_buf.as_path(), recursive));
}
if is_useful_input(&entry) {
return Some(vec![path_buf]);
}
return None;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if recursive && path_buf.is_dir() {
return Some(get_svg_input_paths(path_buf.as_path(), recursive));
}
if is_useful_input(&entry) {
return Some(vec![path_buf]);
}
return None;
if recursive && path_buf.is_dir() {
Some(get_svg_input_paths(path_buf.as_path(), recursive))
} else if is_useful_input(&entry) {
Some(vec![path_buf])
} else {
None
}

@DerZade DerZade requested a review from flother February 13, 2023 20:35
Copy link
Owner

@flother flother left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brilliant, thanks for taking the time to add this

@flother flother merged commit 737f5ed into flother:master Feb 13, 2023
@DerZade
Copy link
Contributor Author

DerZade commented Feb 13, 2023

Thanks a lot for the most pleasant OSS experience I had in a long time :)

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.

Include sub directories
2 participants