mirror of https://github.com/pwndbg/pwndbg
ArgparsedCommand: fix `help cmd` and `cmd --help` behavior (#1108)
* ArgparsedCommand: fix `help cmd` and `cmd --help` behavior Before this commit there was always a mismatch of what was displayed when the user did `<command> --help` or `help <command>`. With those changes, we fetch the help string from the argument parser and render it as the command object's `self.__doc__`, so that it will be displayed during `help <command>`. Previously, we only displayed the command description during help. * fix the pwndbg [filter] command that was broken in previous commit
This commit is contained in:
parent
299f30be73
commit
d12b6ecefc
|
@ -1,5 +1,6 @@
|
|||
import argparse
|
||||
import functools
|
||||
import io
|
||||
|
||||
import gdb
|
||||
|
||||
|
@ -321,13 +322,12 @@ class _ArgparsedCommand(Command):
|
|||
else:
|
||||
self.parser.prog = command_name
|
||||
|
||||
# TODO/FIXME: Can we also append the generated positional args?
|
||||
# E.g. "-f --flag This does something"
|
||||
doc = self.parser.description.strip()
|
||||
if self.parser.epilog:
|
||||
doc += "\n" + self.parser.epilog
|
||||
|
||||
self.__doc__ = function.__doc__ = doc
|
||||
file = io.StringIO()
|
||||
self.parser.print_help(file)
|
||||
file.seek(0)
|
||||
self.__doc__ = file.read()
|
||||
# Note: function.__doc__ is used in the `pwndbg [filter]` command display
|
||||
function.__doc__ = self.parser.description.strip()
|
||||
|
||||
super(_ArgparsedCommand, self).__init__(function, command_name=command_name, *a, **kw)
|
||||
|
||||
|
|
Loading…
Reference in New Issue