Skip to content

Commit

Permalink
recommended changes
Browse files Browse the repository at this point in the history
  • Loading branch information
narmstro2020 committed Oct 24, 2024
1 parent 8480f6e commit 5418314
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
17 changes: 17 additions & 0 deletions commands2/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,23 @@ def select(
"""
return SelectCommand(commands, selector)

def fork(
*commands: Command
) -> Command:
"""
Create a command to run "forked" by wrapping the provided commands in a ScheduleCommand. Use this for
"forking off" from command compositions when the user does not wish to extend the command's
requirements to the entire command composition. Note that if run from a composition, the
composition will not know about the status of the scheduled commands, and will treat this
command as finishing instantly. Multiple commmands can be added to this and will be schedule in order.,
see the `WPILib docs <https://docs.wpilib.org/en/stable/docs/software/commandbased/command-compositions.html#scheduling-other-commands>`_ for a full explanation.
:param commands: commands to schedule in order
:returns: the command
"""
from .schedulecommand import ScheduleCommand
return ScheduleCommand(commands)

Check failure on line 183 in commands2/cmd.py

View workflow job for this annotation

GitHub Actions / check-mypy

Argument 1 to "ScheduleCommand" has incompatible type "tuple[Command, ...]"; expected "Command"


def sequence(*commands: Command) -> Command:
"""
Expand Down
8 changes: 4 additions & 4 deletions commands2/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from .parallelcommandgroup import ParallelCommandGroup
from .repeatcommand import RepeatCommand
from .proxycommand import ProxyCommand
from .schedulecommand import ScheduleCommand
from .conditionalcommand import ConditionalCommand
from .wrappercommand import WrapperCommand

Expand Down Expand Up @@ -384,21 +385,20 @@ def asProxy(self) -> ProxyCommand:

return ProxyCommand(self)

def fork(self, *commands: Command) -> ProxyCommand:
def fork(self, *commands: Command) -> ScheduleCommand:
"""
Decorates this command to run "forked" by wrapping it in a ScheduleCommand. Use this for
"forking off" from command compositions when the user does not wish to extend the command's
requirements to the entire command composition. Note that if run from a composition, the
composition will not know about the status of the scheduled commands, and will treat this
command as finishing instantly. Commands can be added to this and will be scheduled in order
with this command scheduled first., see the `WPILib docs <https://docs.wpilib.org/en/stable/docs/software/commandbased/command-compositions.html#scheduling-other-commands>`_ for a full explanation.
command as finishing instantly., see the `WPILib docs <https://docs.wpilib.org/en/stable/docs/software/commandbased/command-compositions.html#scheduling-other-commands>`_ for a full explanation.
:param other: other commands to schedule along with this one. This command is scheduled first.
:returns: the decorated command
"""
from .schedulecommand import ScheduleCommand

return ScheduleCommand(self, [self] + commands)
return ScheduleCommand(self)

def unless(self, condition: Callable[[], bool]) -> ConditionalCommand:
"""
Expand Down

0 comments on commit 5418314

Please sign in to comment.