Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions commands2/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,26 @@ def startRun(
)


def startRunEnd(
start: Callable[[], Any],
run: Callable[[], Any],
end: Callable[[], Any],
*requirements: Subsystem
) -> Command:
"""
Constructs a command that runs an action once, and then runs an action every iteration until interrupted,
and then runs a third action.

:param start the action to run on start
:param run the action to run every iteration
:param end the action to run on interrupt
:returns: the command
"""
return FunctionalCommand(
start, run, lambda interrupted: end(), lambda: False, *requirements
)


def print_(message: str) -> Command:
"""
Constructs a command that prints a message and finishes.
Expand Down
21 changes: 21 additions & 0 deletions commands2/subsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,27 @@ def startRun(self, start: Callable[[], None], run: Callable[[], None]) -> Comman

return startRun(start, run, self)

def startRunEnd(
self,
start: Callable[[], None],
run: Callable[[], None],
end: Callable[[], None],
) -> Command:
"""
Constructs a command that runs an action once, and then runs an action
every iteration until interrupted, and then runs a third action.
every iteration until interrupted, and then runs a third action. Requires
this subsystem.

:param start the action to run on start
:param run the action to run every iteration
:param end the action to run on interrupt
:returns: the command
"""
from .cmd import startRunEnd

return startRunEnd(start, run, end, self)

def idle(self) -> Command:
"""
Constructs a command that does nothing until interrupted. Requires this subsystem.
Expand Down