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 working-directory attribute #2438

Merged
merged 12 commits into from
Nov 27, 2024

Conversation

bcheidemann
Copy link
Contributor

Closes #2082

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.

Reviewed, see comments!

src/recipe.rs Outdated
}

let working_dir = self
Copy link
Owner

Choose a reason for hiding this comment

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

I think this is better implemented as a for loop:

let working_directory = context.working_directory();

for attribute in self.attributes {
  if let Attribute::WorkingDirectory(dir) = attribute {
    return Some(working_directory.join(dir.cooked);
  }
}

Some(working_directory)

Also note the use of cooked, which is the contents of the string literal after processing escape sequences.

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 think this is better implemented as a for loop

Yup, the suggested for loop reads better and is more concise. Just curious, is there any other reason you suggested this refactor?

Also note the use of cooked, which is the contents of the string literal after processing escape sequences.

Good to know - thanks for the info!

echo "$(basename "$PWD")"

[working-directory('bar')]
[working-directory('baz')]
Copy link
Owner

Choose a reason for hiding this comment

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

Duplicate working directory attributes should be an error.

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.

Sorry for taking so long to get this in! I made [no-cd] and [working-directory] conflict, so you can't have them both on a recipe. I also added an expect_file function to the test runner, which allowed the tests to be simplified, since you can touch a file and check that a file in the expected directory was created.

@casey casey enabled auto-merge (squash) November 27, 2024 23:49
@casey casey merged commit fdc9245 into casey:master Nov 27, 2024
5 checks passed
@bcheidemann
Copy link
Contributor Author

Thanks @casey! Looking forward to using this in my projects 😍

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.

Add [cd(DIR)] attribute
2 participants