3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 09:19:23 +01:00

utils: add an IRCParser class based off argparse, modified from @IotaSpencer's code

Closes #6.
This commit is contained in:
James Lu 2017-02-21 21:45:43 -08:00
parent 02faa3fcb6
commit 0125c544ee

View File

@ -10,6 +10,7 @@ import re
import importlib
import os
import collections
import argparse
from .log import log
from . import world, conf
@ -27,6 +28,11 @@ class NotAuthorizedError(Exception):
"""
pass
class InvalidArgumentsError(TypeError):
"""
Exception raised (by IRCParser and potentially others) when a bot command is given invalid arguments.
"""
class IncrementalUIDGenerator():
"""
Incremental UID Generator module, adapted from InspIRCd source:
@ -547,3 +553,11 @@ def wrapArguments(prefix, args, length, separator=' ', max_args_per_line=0):
strings.append(buf)
return strings
class IRCParser(argparse.ArgumentParser):
"""
Wrapper around argparse.ArgumentParser, without quitting on usage errors.
"""
def error(self, message):
raise InvalidArgumentsError(message)