-
Notifications
You must be signed in to change notification settings - Fork 7
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
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--recursive Include images from subdirectories | |
--recursive Include images in sub-directories |
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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.
pub fn get_svg_input_paths(path: &Path, recurse: bool) -> Vec<PathBuf> { | |
pub fn get_svg_input_paths(path: &Path, recursive: bool) -> Vec<PathBuf> { |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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
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)); |
There was a problem hiding this comment.
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)); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's tighten up the whitespace
There was a problem hiding this comment.
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]); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
/// 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`). |
There was a problem hiding this comment.
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?
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?
|
There was a problem hiding this 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
|
||
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 | |
} |
There was a problem hiding this 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
Thanks a lot for the most pleasant OSS experience I had in a long time :) |
Add
--recursive
option and therefore fix #42.This PR includes two breaking changes to the public API:
recurse
) tospreet::fs::get_svg_input_paths
base_path
) tospreet::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 🙈