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 a confirm attribute for recipes #1723

Merged
merged 23 commits into from
Nov 16, 2023
Merged

Conversation

Hwatwasthat
Copy link
Contributor

This would add a "Confirm" attribute that requests confirmation before running a recipe. Runs prior to evaluation, and defaults to not running. Potential solution to issue #1711.

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.

I just added some comments, and I thought of something else: If a recipe doesn't run, any recipe in the current invocation which depends on that recipe should also not run.

.gitignore Outdated Show resolved Hide resolved
src/attribute.rs Outdated
@@ -13,6 +13,7 @@ pub(crate) enum Attribute {
Private,
Unix,
Windows,
Confirm
Copy link
Owner

Choose a reason for hiding this comment

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

These enum variants should be sorted.

src/recipe.rs Outdated
@@ -63,6 +63,16 @@ impl<'src, D> Recipe<'src, D> {
self.name.line
}

pub(crate) fn confirm(&self) -> bool {
Copy link
Owner

Choose a reason for hiding this comment

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

This function should be fallible, since read_line can fail, so it should return RunResult<bool>

src/recipe.rs Outdated Show resolved Hide resolved
src/recipe.rs Outdated Show resolved Hide resolved
Hwatwasthat and others added 6 commits November 13, 2023 09:11
Corrected format

Co-authored-by: Casey Rodarmor <[email protected]>
Removed extraneous whitespace

Co-authored-by: Casey Rodarmor <[email protected]>
Allow for full word response in confirmation, allow for failure case of read_line.

Co-authored-by: Casey Rodarmor <[email protected]>
a depencency that requires confirmation is denied.
@Hwatwasthat
Copy link
Contributor Author

I just added some comments, and I thought of something else: If a recipe doesn't run, any recipe in the current invocation which depends on that recipe should also not run.

I've added in the confirmation during the running of dependencies. Now, if a recipe that requires confirmation is run as a dependency and is not confirmed then it will return an error of type DependencyNotConfirmed, which I could only find a way to insert the name of the dependency being run, I can't find an easy way to inject the parents name without adding in a lot more convolution.

The confirmation is carried out at the start of the Justfile::run_recipe function, as I couldn't see another place to put it that would prevent anything running and would allow the returning of an error rather than the ok of a single recipe that is being run (as that would stop any later recipes that were from running as I understand it, which is not the intended use of confirmation (again, as I understand it).

@Hwatwasthat
Copy link
Contributor Author

Apologies, on testing a bit I realised that I've added in a double confirm. I'll figure out the best way to resolve this and then update the pull.

@casey
Copy link
Owner

casey commented Nov 14, 2023

Aside from the double confirm, that all sounds good. I think returning an error if a recipe isn't confirmed is sensible. I think that if we get to a recipe that needs confirmation, and it isn't confirmed, we can abort the whole run, and not run any other recipes. Although it is true that we could run any recipes which aren't dependencies of the unconfirmed recipe, not running them doesn't seem like a big deal.

Also, this will require a couple of tests: One that a recipe that requires and receives confirmation runs, and one that a recipe which requires confirmation but doesn't receive it does not run.

@casey
Copy link
Owner

casey commented Nov 14, 2023

Also, if you feel like adding a --yes flag that confirms all recipes (per this comment #1711 (comment)) which seems useful, go for it, otherwise it can be left to another PR.

@Hwatwasthat
Copy link
Contributor Author

Aside from the double confirm, that all sounds good. I think returning an error if a recipe isn't confirmed is sensible. I think that if we get to a recipe that needs confirmation, and it isn't confirmed, we can abort the whole run, and not run any other recipes. Although it is true that we could run any recipes which aren't dependencies of the unconfirmed recipe, not running them doesn't seem like a big deal.

Also, this will require a couple of tests: One that a recipe that requires and receives confirmation runs, and one that a recipe which requires confirmation but doesn't receive it does not run.

Ok, that makes things easier then, I've got a version working that does that so I'll just plow on with it. Tests to come with that in the next commit.

@Hwatwasthat
Copy link
Contributor Author

Also, if you feel like adding a --yes flag that confirms all recipes (per this comment #1711 (comment)) which seems useful, go for it, otherwise it can be left to another PR.

I was just wondering on the name. yes is a bit ambiguous, maybe --force-confirm (just to make it clear), I feel like --force or --no-confirm doesn't work, as force is ambiguous and no confirm reads to me as the inverse (automatically denying confirm stuff). I have a flag working, right now it's --yes.

@Hwatwasthat Hwatwasthat marked this pull request as draft November 14, 2023 18:22
Updated readme to reflect new attribute, and added a TOC.
Added new error type, NotConfirmed, which returns the name of the recipe
that was not confirmed for running.
@Hwatwasthat Hwatwasthat marked this pull request as ready for review November 16, 2023 09:13
@casey casey enabled auto-merge (squash) November 16, 2023 23:50
@casey casey merged commit 9415bee into casey:master Nov 16, 2023
5 checks passed
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.

I tweaked a few error messages, as well as printed the error confirmation message to stderr, which is also line-buffered, so no need to flush.

Thanks for the PR!

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