-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap commands in __main__ to prepend 'covimerage: ' prefix with errors.
- Loading branch information
Showing
4 changed files
with
70 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,39 @@ | ||
if __name__ == '__main__': | ||
def wrap_for_errormsg(f, *args, **kwargs): | ||
import logging | ||
from .logger import handler | ||
|
||
handler.setFormatter(logging.Formatter('covimerage: %(message)s')) | ||
|
||
try: | ||
f(*args, standalone_mode=False, **kwargs) | ||
except Exception as exc: | ||
from click.exceptions import ClickException | ||
if isinstance(exc, ClickException): | ||
import re | ||
import sys | ||
from click.utils import echo | ||
from ._compat import StringIO | ||
|
||
# Use `show()` to get extended message with UsageErrors. | ||
out = StringIO() | ||
exc.show(file=out) | ||
out.seek(0) | ||
msg = re.sub("^Error: ", "covimerage: Error: ", out.read(), | ||
flags=re.MULTILINE) | ||
echo(msg, err=True, nl=False) | ||
sys.exit(exc.exit_code) | ||
raise | ||
|
||
|
||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters