-
Notifications
You must be signed in to change notification settings - Fork 630
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 Commands.runIf(...) as command factory method to Commands #7808
base: main
Are you sure you want to change the base?
Conversation
This PR modifies commands. Please open a corresponding PR in Python Commands and include a link to this PR. |
/** | ||
* Runs a command if the boolean selector function is true. | ||
* | ||
* @param selector the selector function |
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.
Instead of selector I'd refer to this as a condition
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.
@rzblue With this change should I move the command out of the Selector Commands
section of the Commands.java file? If so where should it go instead?
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.
It can stay in the Selecting section (along with either
etc)
@@ -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. |
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.
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()
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.
I edited the code so it should be clear now!
Apologies for the late response!
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.
Nice work so far!
@@ -166,6 +166,19 @@ 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 otherwise it does nothing and exits. |
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.
* Runs a command if the boolean condition function is true otherwise it does nothing and exits. | |
* Runs a command if the boolean condition function is true. Otherwise it does nothing and exits | |
* (but still has the same requirements as the command, interrupting any commands with shared | |
* requirements). |
I could see some people reading "does nothing" as "has no side effects" and being surprised/confused when it interrupts commands with shared requirements. Splitting the sentence is just personal preference that helps me parse it better, but go ahead and structure it how you think is best.
* @param onTrue the command to run if the condition function returns true | ||
* @return the command | ||
* @see ConditionalCommand | ||
* @see {@link Commands#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.
* @see {@link Commands#none()} | |
* @see Commands#none() |
When running the java formatting CI locally, it didn't seem to like using @link
in the @see
. This has the following javadoc output (you can run ./gradlew wpilibNewCommands:javadoc
locally and open wpilibNewCommands/build/docs/javadoc/allclasses-index.html
to see the javadoc output):
(This is including the other suggested change)
Intends to close #7807
Adds the equivalent to an if statement for Commands.java.
It runs
Commands.either
under the hood withCommands.none()
as theonFalse
parameter.I haven't coded a C++ or python version for this as I'm not confident enough in my coding ability in those languages.