Skip to content

Commit 138ded2

Browse files
committed
Add startRun command factory
1 parent 1d78b88 commit 138ded2

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

commands2/cmd.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,20 @@ def runEnd(
9494
lambda: None, run, lambda interrupted: end(), lambda: False, *requirements
9595
)
9696

97+
def startRun(
98+
start: Callable[[], Any], run: Callable[[], Any], *requirements: Subsystem
99+
) -> Command:
100+
"""
101+
Constructs a command that runs an action once and another action every iteration until interrupted.
102+
103+
:param start: the action to run on start
104+
:param run: the action to run every iteration
105+
:param requirements: subsystems the action requires
106+
:returns: the command
107+
"""
108+
return FunctionalCommand(
109+
start, run, lambda interrupt: None, lambda: False, *requirements
110+
)
97111

98112
def print_(message: str) -> Command:
99113
"""

commands2/subsystem.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,18 @@ def runEnd(self, run: Callable[[], None], end: Callable[[], None]) -> Command:
156156

157157
return runEnd(run, end, self)
158158

159+
def startRun(self, start: Callable[[], None], run: Callable[[], None]) -> Command:
160+
"""
161+
Constructs a command that runs an action once and another action every iteration until interrupted. Requires this subsystem.
162+
163+
:param start: the action to run on start
164+
:param run: the action to run every iteration
165+
:returns: the command
166+
"""
167+
from .cmd import startRun
168+
169+
return startRun(start, run, self)
170+
159171
#
160172
# From SubsystemBase
161173
#

0 commit comments

Comments
 (0)