Skip to content

Commit

Permalink
Wrap commands in __main__ to prepend 'covimerage: ' prefix with errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed committed Oct 23, 2018
1 parent 75300f1 commit 19cd521
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
25 changes: 24 additions & 1 deletion covimerage/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
if __name__ == '__main__':
def wrap_for_errormsg(f, *args, **kwargs):
try:
f(*args, standalone_mode=False, **kwargs)
except Exception as exc:
from click.exceptions import ClickException
if isinstance(exc, ClickException):
import sys
from click.utils import echo

msg = 'covimerage: error: %s' % (exc.format_message(),)
echo(msg, err=True)
sys.exit(2)


def main():
from .cli import main
wrap_for_errormsg(main.main, prog_name='covimerage')


def run():
from .cli import run
wrap_for_errormsg(run.main, prog_name='covimerage-run')


if __name__ == '__main__':
main()
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def run(self):
packages=['covimerage'],
entry_points={
'console_scripts': [
'covimerage=covimerage.cli:main',
'covimerage-run=covimerage.cli:run',
'covimerage=covimerage.__main__:main',
'covimerage-run=covimerage.__main__:run',
],
},
use_scm_version={
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
def test_dunder_main_run(capfd):
assert call([sys.executable, '-m', 'covimerage']) == 0
out, err = capfd.readouterr()
assert out.startswith('Usage: __main__')
assert out.startswith('Usage: covimerage')


def test_dunder_main_run_help(capfd):
Expand Down

0 comments on commit 19cd521

Please sign in to comment.