Skip to content

Add Commands.runIf(...) as command factory method to Commands #7808

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,18 @@ public static Command either(Command onTrue, Command onFalse, BooleanSupplier se
return new ConditionalCommand(onTrue, onFalse, selector);
}

/**
* Runs a command if the boolean condition function is true.
Copy link
Member

Choose a reason for hiding this comment

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

Make it more obvious in the doc that if the condition is false, the command will do nothing and exit (meaning it will still grab requirements etc) -- you can link to none()

Copy link
Author

Choose a reason for hiding this comment

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

I edited the code so it should be clear now!
Apologies for the late response!

*
* @param condition the condition function
* @param onTrue the command to run if the condition function returns true
* @return the command
* @see ConditionalCommand
*/
public static Command runIf(BooleanSupplier condition, Command onTrue) {
return onTrue.onlyIf(condition);
}

/**
* Runs one of several commands, based on the selector function.
*
Expand Down