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: allow groups on submodules #2263

Merged
merged 2 commits into from
Jul 21, 2024
Merged

Conversation

jmwoliver
Copy link
Contributor

@jmwoliver jmwoliver commented Jul 19, 2024

Hello! I've been working on a fix for #2243.

I added the whole attributes object instead of just passing around the group like how the doc is. My rationale for this was to make it easier to have access to anything stored in the attributes in the future, let me know if that is the wrong path though.

This is my first time contributing to just, I'm open to any feedback!

Copy link
Owner

@casey casey left a comment

Choose a reason for hiding this comment

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

Nice! I think I would avoid putting storing all attributes on a Justfile, for a couple reasons. One abstract reason is that I try not to make changes in anticipation future needs. There's a good chance those future needs may manifest, or they might manifest differently than expected. And one concrete reasons is that attributes serialize in a somewhat odd way, so they will be difficult to parse using jq, if you use --dump --dump-format json to dump a justfile, whereas a groups: Vec<String> field will be easy to parse, so I think I would separate out groups and just store the group names on Justfile.

@jmwoliver
Copy link
Contributor Author

@casey Thanks for the feedback! Great points, I'll get this updated to just pass in the group names instead.

@jmwoliver jmwoliver force-pushed the jmw/mod-groups branch 3 times, most recently from 09ab72e to 42f6c7f Compare July 19, 2024 16:13
@jmwoliver
Copy link
Contributor Author

@casey I switched to passing around groups: Vec<String>, hopefully this looks better!

@jmwoliver
Copy link
Contributor Author

Fixed linter errors and re-pushed.

Copy link
Owner

@casey casey left a comment

Choose a reason for hiding this comment

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

Nice, left some initial comments! To check if the PR will pass CI, run just ci, which runs clippy and errors on warnings.

src/justfile.rs Outdated Show resolved Hide resolved
src/justfile.rs Outdated Show resolved Hide resolved
@@ -771,6 +771,88 @@ fn doc_attribute_on_module() {
.run();
}

#[test]
fn group_attribute_on_module() {
Copy link
Owner

Choose a reason for hiding this comment

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

We should have a test for the ordering of submodules in groups if --unsorted is used.

My first thought was that submodules should be ordered based on their position in the justfile. However, I'm now not sure if that's correct. I think it's natural to have submodules all declared together at the top or bottom of a justfile, and natural to list submodules at the end of each group.

So maybe my comment above is off, and we should, instead of using submodule.name.unwrap().offset in the ordering key, use usize::MAX instead.

Copy link
Contributor Author

@jmwoliver jmwoliver Jul 20, 2024

Choose a reason for hiding this comment

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

Hm, I tested setting submodule.name.unwrap().offset vs. usize::MAX, and both have the same behavior. Both implementations output the submodules at the end of a group because of how we output recipes and then submodules in subcommand.rs:

for (i, group) in ordered.into_iter().enumerate() {
  for recipe in recipes {...}
  for (i, submodule) in submodules.iter().enumerate() {...}
}

If we wanted the ability to order based on the submodule's position in the justfile, then we would need to interleave the recipes and submodules. But since it sounds like we want them at the end of a group, I'll go with usize::MAX. Let me know if you disagree.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added tests for --unsorted with and without --list-submodules. I ended up going with submodule.name.unwrap().offset because I think that better guarantees the submodules are ordered how they appear in the justfile at the bottom of a group.

@jmwoliver
Copy link
Contributor Author

@casey Thanks for the all the great feedback and the just ci tip. I've updated everything with your recommendation, let me know how it looks!

Copy link
Owner

@casey casey left a comment

Choose a reason for hiding this comment

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

Nice, looks good to me!

@casey casey enabled auto-merge (squash) July 21, 2024 23:34
@casey casey merged commit 16aad6e into casey:master Jul 21, 2024
5 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.

2 participants