cli: add --debugger option
1 files changed, 12 insertions(+), 6 deletions(-)

M lairucrem/__main__.py
M lairucrem/__main__.py +12 -6
@@ 90,7 90,7 @@ async def activate_notify(callback, *, l
         watcher.close()
 
 
-def run(rev=None, debug=False, inotify=False, enable_commands=False):
+def run(rev=None, debug=False, debugger=False, inotify=False, enable_commands=False):
     ctrl = controler.maincontroler(rev=rev)
     if enable_commands:
         ctrl.enable_commands()

          
@@ 98,8 98,8 @@ def run(rev=None, debug=False, inotify=F
     set_main_widget_policy(ctrl.get_widget)
     loop = get_main_loop()
     loop._unhandled_input = ctrl.unhandled_input
-    if debug:
-        debug_mode(loop)
+    if debug or debugger:
+        debug_mode(loop, debugger)
     utils.ensure_one(register_branch_colors).ensure(loop)
     utils.ensure_one(register_topic_colors).ensure(loop)
     if inotify:

          
@@ 135,6 135,9 @@ def parse_args():
     parser.add_argument('--debug',
                         help='enable debug mode',
                         default=False, action='store_true')
+    parser.add_argument('--debugger',
+                        help='enable debugger at startup',
+                        default=False, action='store_true')
     parser.add_argument('--with-hg', metavar='PATH',
                         default=hgpath,
                         help=('hg script path. Can be set using the '

          
@@ 163,10 166,10 @@ def parse_args():
     return parser.parse_args()
 
 
-def debug_mode(mainloop):
+def debug_mode(mainloop, debugger):
     from lairucrem.utils import monkeypatch
     try:
-        from IPython.core.debugger import Pdb
+        from IPython.core.debugger import Pdb, set_trace
     except ImportError:
         from pdb import set_trace, Pdb
     ctx = []

          
@@ 188,6 191,8 @@ def debug_mode(mainloop):
         except Exception:
             pass
         set_trace()
+    if debugger:
+        set_trace()
 
 
 def setup_logging(logpath):

          
@@ 242,7 247,8 @@ def main():
     if opts.key_bindings:
         apply_keybindings(opts.key_bindings)
     try:
-        run(rev=opts.rev, debug=opts.debug, inotify=not opts.disable_inotify,
+        run(rev=opts.rev, debug=opts.debug, debugger=opts.debugger,
+            inotify=not opts.disable_inotify,
             enable_commands=not opts.view_only)
     except (HgNotFoundError, RepositoryNotFound) as error:
         print(error)