RegexCommand's now get matched last

master
Jef Roosens 2020-08-26 13:05:56 +02:00
parent 78290554bd
commit 46d8d4322e
1 changed files with 6 additions and 3 deletions

View File

@ -6,7 +6,7 @@ from __future__ import annotations
from functools import cached_property
# Own imports
from .decorators import Command, Daemon, Default
from .decorators import Command, Daemon, Default, RegexCommand
# Typing imports
from typing import TYPE_CHECKING
@ -33,8 +33,11 @@ class ModuleMeta:
@cached_property
def commands(self) -> List[Command]:
# This also matches RegexCommand objects
# TODO: sort this to put RegexCommand's at the back
return self._filter_attrs(lambda val: isinstance(val, Command))
# The sort puts all the RegexCommand objects at the back, making them
# be matched last
return sorted(self._filter_attrs(lambda val: isinstance(val, Command)),
key=lambda x: isinstance(x, RegexCommand))
@cached_property
def daemons(self) -> List[Daemon]: