Make command arguments map optional and fix optional command arguments
This commit is contained in:
parent
a4fb18038c
commit
fd14a38546
@ -31,7 +31,7 @@ class Argument(SerializableAttrs['Argument']):
|
|||||||
@dataclass
|
@dataclass
|
||||||
class Command(SerializableAttrs['Command']):
|
class Command(SerializableAttrs['Command']):
|
||||||
syntax: str
|
syntax: str
|
||||||
arguments: Dict[str, Argument]
|
arguments: Dict[str, Argument] = {}
|
||||||
description: str = None
|
description: str = None
|
||||||
|
|
||||||
|
|
||||||
@ -80,7 +80,9 @@ class ParsedCommand:
|
|||||||
arg = command.arguments.get(word, None)
|
arg = command.arguments.get(word, None)
|
||||||
if arg is not None and len(word) > 0:
|
if arg is not None and len(word) > 0:
|
||||||
argument_encountered = True
|
argument_encountered = True
|
||||||
regex = f"({arg.matches})" if arg.required else f"(?:{arg.matches})?"
|
regex = f"({arg.matches})"
|
||||||
|
if not arg.required:
|
||||||
|
regex += "?"
|
||||||
self.arguments.append(word)
|
self.arguments.append(word)
|
||||||
regex_builder.append(regex)
|
regex_builder.append(regex)
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user