Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
hoefler02 committed Jun 6, 2021
1 parent 908db30 commit fac0fb4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion docs/commands/aliases.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ aliases rm [alias]

### Listing Aliases

One can list aliases by using the `aliases list` command. Some sample output of this
One can list aliases by using the `aliases ls` command. Some sample output of this
command is seen below.

```
Expand Down
31 changes: 16 additions & 15 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -10484,10 +10484,10 @@ def lookup_command(self, cmd):

@register_command
class AliasesCommand(GenericCommand):
"""Base command to add, remove, or list aliases"""
"""Base command to add, remove, or list aliases."""

_cmdline_ = "aliases"
_syntax_ = "{:s} (add|rm|list)".format(_cmdline_)
_syntax_ = "{:s} (add|rm|ls)".format(_cmdline_)

def __init__(self):
super().__init__(prefix=True)
Expand All @@ -10499,7 +10499,7 @@ def do_invoke(self, argv):

@register_command
class AliasesAddCommand(AliasesCommand):
"""Command to add aliases"""
"""Command to add aliases."""

_cmdline_ = "aliases add"
_syntax_ = "{0} [ALIAS] [COMMAND]".format(_cmdline_)
Expand All @@ -10519,7 +10519,7 @@ def do_invoke(self, argv):

@register_command
class AliasesRmCommand(AliasesCommand):
"""Command to remove aliases"""
"""Command to remove aliases."""

_cmdline_ = "aliases rm"
_syntax_ = "{0} [ALIAS]".format(_cmdline_)
Expand All @@ -10530,23 +10530,24 @@ def __init__(self):

def do_invoke(self, argv):
global __aliases__
if (len(argv) != 1):
if len(argv) != 1:
self.rm_usage()
return
numaliases = len(__aliases__)
__aliases__ = [alias for alias in __aliases__ if alias._alias != argv[0]]
if numaliases == len(__aliases__):
err("{0} not found in aliases.".format(argv[0]))
return
try:
alias_to_remove = next(filter(lambda x: x._alias == argv[0], __aliases__))
__aliases__.remove(alias_to_remove)
except (ValueError, StopIteration) as e:
err("{0} not found in aliases.".format(argv[0]))
return
GefSaveCommand().invoke(None, False)
# TODO: reload GEF so that the alias no longer works in the current session?
gef_print("You must reload GEF for alias removals to apply.")
return

@register_command
class AliasesListCommand(AliasesCommand):
"""Command to list aliases"""
"""Command to list aliases."""

_cmdline_ = "aliases list"
_cmdline_ = "aliases ls"
_syntax_ = _cmdline_

def __init__(self):
Expand All @@ -10555,8 +10556,8 @@ def __init__(self):

def do_invoke(self, argv):
ok("Aliases defined:")
for _alias in __aliases__:
gef_print("{:30s} {} {}".format(_alias._alias, RIGHT_ARROW, _alias._command))
for a in __aliases__:
gef_print("{:30s} {} {}".format(a._alias, RIGHT_ARROW, a._command))
return

class GefTmuxSetup(gdb.Command):
Expand Down
12 changes: 6 additions & 6 deletions tests/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,17 +520,17 @@ def test_cmd_highlight(self):

def test_cmd_aliases(self):
# test add functionality
add_res = gdb_start_silent_cmd("aliases add a b")
add_res = gdb_start_silent_cmd("aliases add alias_function_test example")
self.assertNoException(add_res)
# test list functionality
list_res = gdb_start_silent_cmd("aliases list")
list_res = gdb_start_silent_cmd("aliases ls")
self.assertNoException(list_res)
self.assertIn("a → b", list_res)
self.assertIn("alias_function_test", list_res)
# test rm functionality
rm_res = gdb_start_silent_cmd("aliases rm a")
rm_res = gdb_start_silent_cmd("aliases rm alias_function_test")
self.assertNoException(rm_res)
rm_list_res = gdb_start_silent_cmd("aliases list")
self.assertNotIn("a → b", rm_list_res)
rm_list_res = gdb_start_silent_cmd("aliases ls")
self.assertNotIn("alias_function_test", rm_list_res)
return


Expand Down

0 comments on commit fac0fb4

Please sign in to comment.