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 startRun command factory #64

Merged
merged 1 commit into from
May 6, 2024
Merged
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
16 changes: 16 additions & 0 deletions commands2/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ def runEnd(
)


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

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


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

return runEnd(run, end, self)

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

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

return startRun(start, run, self)

#
# From SubsystemBase
#
Expand Down
Loading