Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/debugcommands.py @ 50014:8f76a41ee465
debugshell: allow commands to be specified as a CLI argument
Add a `--command` option to `hg debugshell` that allows the user to pass in
Python code to evaluate directly from the command line. This was inspired by
the `--command` option present in Facebook's Sapling fork of Mercurial,
which in turn was inspired by the `-c` option of the Python interpreter
itself. It is particularly useful for writing tests, especially for getting
visibility into things that otherwise aren't exposed via debug commands.
author | Arun Kulshreshtha <akulshreshtha@janestreet.com> |
---|---|
date | Thu, 19 Jan 2023 11:12:20 -0500 |
parents | 88b81dc2d82b |
children | 637d46c5b1fa |
comparison
equal
deleted
inserted
replaced
50013:86958104b6ca | 50014:8f76a41ee465 |
---|---|
3784 ui.writenoi18n(b'path %s\n' % k) | 3784 ui.writenoi18n(b'path %s\n' % k) |
3785 ui.writenoi18n(b' source %s\n' % v[0]) | 3785 ui.writenoi18n(b' source %s\n' % v[0]) |
3786 ui.writenoi18n(b' revision %s\n' % v[1]) | 3786 ui.writenoi18n(b' revision %s\n' % v[1]) |
3787 | 3787 |
3788 | 3788 |
3789 @command(b'debugshell', optionalrepo=True) | 3789 @command( |
3790 def debugshell(ui, repo): | 3790 b'debugshell', |
3791 [ | |
3792 ( | |
3793 b'c', | |
3794 b'command', | |
3795 b'', | |
3796 _(b'program passed in as a string'), | |
3797 _(b'COMMAND'), | |
3798 ) | |
3799 ], | |
3800 _(b'[-c COMMAND]'), | |
3801 optionalrepo=True, | |
3802 ) | |
3803 def debugshell(ui, repo, **opts): | |
3791 """run an interactive Python interpreter | 3804 """run an interactive Python interpreter |
3792 | 3805 |
3793 The local namespace is provided with a reference to the ui and | 3806 The local namespace is provided with a reference to the ui and |
3794 the repo instance (if available). | 3807 the repo instance (if available). |
3795 """ | 3808 """ |
3812 site.setcopyright() | 3825 site.setcopyright() |
3813 site.sethelper() | 3826 site.sethelper() |
3814 site.setquit() | 3827 site.setquit() |
3815 except ImportError: | 3828 except ImportError: |
3816 site = None # Keep PyCharm happy | 3829 site = None # Keep PyCharm happy |
3830 | |
3831 command = opts.get('command') | |
3832 if command: | |
3833 compiled = code.compile_command(encoding.strfromlocal(command)) | |
3834 code.InteractiveInterpreter(locals=imported_objects).runcode(compiled) | |
3835 return | |
3817 | 3836 |
3818 code.interact(local=imported_objects) | 3837 code.interact(local=imported_objects) |
3819 | 3838 |
3820 | 3839 |
3821 @command( | 3840 @command( |