[commands] Add convenience factories (#4460)

Co-authored-by: Starlight220 <53231611+Starlight220@users.noreply.github.com>
This commit is contained in:
Eli Barnett
2022-11-28 10:41:25 -05:00
committed by GitHub
parent 42b6d4e3f7
commit 1a59737f40
31 changed files with 1240 additions and 1 deletions

View File

@@ -77,4 +77,52 @@ public interface Subsystem {
default void register() {
CommandScheduler.getInstance().registerSubsystem(this);
}
/**
* Constructs a command that runs an action once and finishes. Requires this subsystem.
*
* @param action the action to run
* @return the command
* @see InstantCommand
*/
default Command runOnce(Runnable action) {
return Commands.runOnce(action, this);
}
/**
* Constructs a command that runs an action every iteration until interrupted. Requires this
* subsystem.
*
* @param action the action to run
* @return the command
* @see RunCommand
*/
default Command run(Runnable action) {
return Commands.run(action, this);
}
/**
* Constructs a command that runs an action once and another action when the command is
* interrupted. Requires this subsystem.
*
* @param start the action to run on start
* @param end the action to run on interrupt
* @return the command
* @see StartEndCommand
*/
default Command startEnd(Runnable start, Runnable end) {
return Commands.startEnd(start, end, this);
}
/**
* Constructs a command that runs an action every iteration until interrupted, and then runs a
* second action. Requires this subsystem.
*
* @param run the action to run every iteration
* @param end the action to run on interrupt
* @return the command
*/
default Command runEnd(Runnable run, Runnable end) {
return Commands.runEnd(run, end, this);
}
}