Skip to content

Commit 4a953ab

Browse files
authored
Merge pull request #64 from ArchdukeTim/startRun
Add startRun command factory
2 parents e2a83dd + 3a4f77b commit 4a953ab

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

commands2/cmd.py

+16
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,22 @@ def runEnd(
9595
)
9696

9797

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

commands2/subsystem.py

+12
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)