Skip to content

Commit e74124e

Browse files
committed
[cmd] Split the command on multiple subcommands for autocompletion
1 parent 64e251d commit e74124e

File tree

2 files changed

+39
-14
lines changed

2 files changed

+39
-14
lines changed

docs/commands/arch.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ There are 3 available sub-commands:
99
gef do magic to detect the architecture by not providing arguments.
1010

1111
![arch](https://imgur.com/a/6JUoOmS)
12-

gef.py

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4768,29 +4768,55 @@ def __set_repeat_count(self, argv: List[str], from_tty: bool) -> None:
47684768

47694769

47704770
@register
4771-
class ArchCommand(GenericCommand):
4771+
class PieCommand(GenericCommand):
47724772
"""Manage the current loaded architecture"""
47734773

47744774
_cmdline_ = "arch"
47754775
_syntax_ = f"{_cmdline_} (list|get|set) ..."
47764776
_example_ = f"{_cmdline_}"
47774777

4778+
def __init__(self) -> None:
4779+
super().__init__(prefix=True)
4780+
return
4781+
4782+
def do_invoke(self, argv: List[str]) -> None:
4783+
if not argv:
4784+
self.usage()
4785+
return
4786+
4787+
@register
4788+
class ArchGetCommand(GenericCommand):
4789+
"""Get the current loaded architecture"""
4790+
4791+
_cmdline_ = "arch get"
4792+
_syntax_ = f"{_cmdline_}"
4793+
_example_ = f"{_cmdline_}"
4794+
47784795
def do_invoke(self, args: List[str]) -> None:
4779-
if len(args) == 0 or args[0] == 'get':
4780-
self._get_cmd()
4781-
elif args[0] == 'set':
4782-
self._set_cmd(*args[1:])
4783-
elif args[0] == 'list':
4784-
self._list_cmd()
4796+
gef_print(f"{Color.greenify('Arch')}: {gef.arch}")
4797+
gef_print(f"{Color.greenify('Reason')}: {gef.arch_reason}")
47854798

4786-
def _get_cmd(self) -> None:
4787-
gef_print(f"{Color.greenify("Arch")}: {gef.arch}")
4788-
gef_print(f"{Color.greenify("Reason")}: {gef.arch_reason}")
47894799

4790-
def _set_cmd(self, arch = None, *args) -> None:
4791-
reset_architecture(arch)
4800+
@register
4801+
class ArchSetCommand(GenericCommand):
4802+
"""Set the current loaded architecture"""
4803+
4804+
_cmdline_ = "arch set"
4805+
_syntax_ = f"{_cmdline_} <arch>"
4806+
_example_ = f"{_cmdline_}"
4807+
4808+
def do_invoke(self, args: List[str]) -> None:
4809+
reset_architecture(args[0] if args else None)
47924810

4793-
def _list_cmd(self) -> None:
4811+
@register
4812+
class ArchListCommand(GenericCommand):
4813+
"""List the available architectures"""
4814+
4815+
_cmdline_ = "arch list"
4816+
_syntax_ = f"{_cmdline_}"
4817+
_example_ = f"{_cmdline_}"
4818+
4819+
def do_invoke(self, args: List[str]) -> None:
47944820
gef_print(Color.greenify("Available architectures:"))
47954821
for arch in __registered_architectures__.keys():
47964822
if type(arch) == str:

0 commit comments

Comments
 (0)