Fix minor errors in displaying the UnixCommand
This commit is contained in:
parent
d6f2d6a305
commit
916d7933aa
1 changed files with 21 additions and 12 deletions
|
|
@ -149,7 +149,9 @@ class UnixCommand(Command):
|
||||||
try:
|
try:
|
||||||
self.opts = self.parser.parse_args(shlex.split(self.args))
|
self.opts = self.parser.parse_args(shlex.split(self.args))
|
||||||
except ParseError as err:
|
except ParseError as err:
|
||||||
self.msg(str(err))
|
msg = str(err)
|
||||||
|
if msg:
|
||||||
|
self.msg(msg)
|
||||||
raise InterruptCommand
|
raise InterruptCommand
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -168,16 +170,17 @@ class EvenniaParser(argparse.ArgumentParser):
|
||||||
prog = prog or command.key
|
prog = prog or command.key
|
||||||
super(EvenniaParser, self).__init__(
|
super(EvenniaParser, self).__init__(
|
||||||
prog=prog, description=description,
|
prog=prog, description=description,
|
||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
conflict_handler='resolve', add_help=False, **kwargs)
|
||||||
conflict_handler='resolve', **kwargs)
|
|
||||||
self.command = command
|
self.command = command
|
||||||
self.post_help = epilog
|
self.post_help = epilog
|
||||||
def n_exit(code=None, msg=None):
|
def n_exit(code=None, msg=None):
|
||||||
if msg:
|
raise ParseError(msg)
|
||||||
raise ParseError(msg)
|
|
||||||
|
|
||||||
self.exit = n_exit
|
self.exit = n_exit
|
||||||
|
|
||||||
|
# Replace the -h/--help
|
||||||
|
self.add_argument("-h", "--hel", nargs=0, action=HelpAction, help="display heeeelp")
|
||||||
|
|
||||||
def format_usage(self):
|
def format_usage(self):
|
||||||
"""Return the usage line."""
|
"""Return the usage line."""
|
||||||
return raw(super(EvenniaParser, self).format_usage())
|
return raw(super(EvenniaParser, self).format_usage())
|
||||||
|
|
@ -185,18 +188,24 @@ class EvenniaParser(argparse.ArgumentParser):
|
||||||
def format_help(self):
|
def format_help(self):
|
||||||
"""Return the parser help, including its epilog."""
|
"""Return the parser help, including its epilog."""
|
||||||
autohelp = raw(super(EvenniaParser, self).format_help())
|
autohelp = raw(super(EvenniaParser, self).format_help())
|
||||||
return autohelp + "\n\n" + self.post_help
|
return "\n" + autohelp + "\n" + self.post_help
|
||||||
|
|
||||||
def print_usage(self, file=None):
|
def print_usage(self, file=None):
|
||||||
"""Print the usage to the caller."""
|
"""Print the usage to the caller."""
|
||||||
if self.command:
|
if self.command:
|
||||||
self.command.msg(ParseError(self.format_usage()))
|
self.command.msg(self.format_usage().strip())
|
||||||
else:
|
|
||||||
raise ParseError(self.format_usage())
|
|
||||||
|
|
||||||
def print_help(self, file=None):
|
def print_help(self, file=None):
|
||||||
"""Print the help to the caller."""
|
"""Print the help to the caller."""
|
||||||
if self.command:
|
if self.command:
|
||||||
self.command.msg(ParseError(self.format_help()))
|
self.command.msg(self.format_help().strip())
|
||||||
else:
|
|
||||||
raise ParseError(self.format_help())
|
|
||||||
|
class HelpAction(argparse.Action):
|
||||||
|
|
||||||
|
"""Override the -h/--he.p."""
|
||||||
|
|
||||||
|
def __call__(self, parser, namespace, values, option_string=None):
|
||||||
|
if parser.command:
|
||||||
|
parser.command.msg(parser.format_help().strip())
|
||||||
|
parser.exit(0, "")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue