|
1 | 1 | # -*- coding: utf-8 -*- |
2 | | -# Copyright (C) 2008-2009, 2013, 2015, 2018 Rocky Bernstein <rocky@gnu.org> |
| 2 | +# Copyright (C) 2008-2009, 2013, 2015, 2018, 2020 Rocky Bernstein <rocky@gnu.org> |
3 | 3 | # |
4 | 4 | # This program is free software: you can redistribute it and/or modify |
5 | 5 | # it under the terms of the GNU General Public License as published by |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | import re |
17 | 17 |
|
| 18 | +from getopt import getopt, GetoptError |
| 19 | + |
18 | 20 | # Our local modules |
19 | 21 | from trepan.processor.command import base_subcmd as Mbase_subcmd |
20 | 22 | from trepan.lib import pp as Mpp |
|
26 | 28 | _with_local_varname = re.compile(r'_\[[0-9+]\]') |
27 | 29 |
|
28 | 30 | class InfoLocals(Mbase_subcmd.DebuggerSubcommand): |
29 | | - """**info locals** [*var1 ...*] |
| 31 | + """**info locals** [-l | --list | | -h --help] |
| 32 | +
|
| 33 | + **info locals** [*var1 ...*] |
30 | 34 |
|
31 | 35 | **info locals** * |
32 | 36 |
|
@@ -54,7 +58,39 @@ def run(self, args): |
54 | 58 | if not self.proc.curframe: |
55 | 59 | self.errmsg("No frame selected") |
56 | 60 | return False |
| 61 | + |
| 62 | + try: |
| 63 | + opts, args = getopt( |
| 64 | + args, |
| 65 | + "hl", |
| 66 | + ["help", "list"], |
| 67 | + ) |
| 68 | + except GetoptError as err: |
| 69 | + # print help information and exit: |
| 70 | + self.errmsg( |
| 71 | + str(err) |
| 72 | + ) # will print something like "option -a not recognized" |
| 73 | + return |
| 74 | + |
| 75 | + list_only = False |
| 76 | + for o, a in opts: |
| 77 | + if o in ("-h", "--help"): |
| 78 | + self.proc.commands["help"].run(["help", "info", "locals"]) |
| 79 | + return |
| 80 | + elif o in ("-l", "--list"): |
| 81 | + list_only = True |
| 82 | + else: |
| 83 | + self.errmsg("unhandled option '%s'" % o) |
| 84 | + pass |
| 85 | + pass |
| 86 | + |
| 87 | + |
57 | 88 | names = list(self.proc.curframe.f_locals.keys()) |
| 89 | + |
| 90 | + if list_only: |
| 91 | + for name in names: |
| 92 | + self.msg(name) |
| 93 | + return |
58 | 94 | if len(args) > 0 and args[0] == '*' : |
59 | 95 | self.section("locals") |
60 | 96 | self.msg(self.columnize_commands(names)) |
|
0 commit comments