From 8f7fe39c27c18d7ae71839baf563c43e1420a597 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 9 Apr 2019 12:17:05 +0200 Subject: [PATCH] Add optional to CommandArgs --- royalnet/utils/command.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/royalnet/utils/command.py b/royalnet/utils/command.py index 6b548d2e..84a26f8e 100644 --- a/royalnet/utils/command.py +++ b/royalnet/utils/command.py @@ -43,6 +43,11 @@ class CommandArgs(list): raise InvalidInputError("Pattern didn't match") return match + def optional(self, index: int) -> typing.Optional: + try: + return self[index] + except IndexError: + return None class Command: """A generic command, called from any source."""