Archived
1
0
Fork 0

update docopt to docopt-ng 0.7.2

This commit is contained in:
yzhh 2021-07-19 13:34:29 +08:00
parent 9eea0351c4
commit 63440959c4
2 changed files with 541 additions and 335 deletions

File diff suppressed because it is too large Load diff

View file

@ -2,14 +2,19 @@ import shlex
from core.docopt import docopt
class InvalidCommandFormatError:
class InvalidCommandFormatError(BaseException):
def __init__(self, *args, **kwargs):
pass
class CommandParser:
def __init__(self, args: str):
self.args = 'Usage:\n' + args
def __init__(self, args: [str, list, tuple]):
if isinstance(args, str):
self.args = f'Usage:\n {args}'
elif isinstance(args, (list, tuple)):
self.args = f'Usage:\n ' + '\n '.join(x for x in args)
else:
raise InvalidCommandFormatError
def parse(self, command):
return docopt(self.args, argvs=shlex.split(command)[1:], help=False)
return docopt(self.args, argvs=shlex.split(command)[1:], default_help=False)