-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·55 lines (43 loc) · 1.61 KB
/
main.py
File metadata and controls
executable file
·55 lines (43 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3
import sys
import click
import cli
if not cli.config.TGBOX_CLI_COMPLETE:
import logging
import warnings
from traceback import format_exception
try:
# This will enable navigation in input
import readline # pylint: disable=unused-import
except (ImportError, ModuleNotFoundError):
pass
logger = logging.getLogger(__name__)
# Disable annoying (in CLI) UserWarning/RuntimeWarning
warnings.simplefilter('ignore', category=UserWarning)
warnings.simplefilter('ignore', category=RuntimeWarning)
def safe_tgbox_cli_startup():
try:
cli.commands.group.cli_group(standalone_mode=False)
except click.exceptions.NoArgsIsHelpError as e:
# Normal behaviour, tells us just to show commands list
cli.tools.terminal.echo(e.format_message())
except Exception as e:
if isinstance(e, (click.Abort, cli.commands.errors.CheckCTXFailed)):
sys.exit(0)
traceback = ''.join(format_exception(
e,
value = e,
tb = e.__traceback__
))
# This will ignore some click exceptions that we really
# don't need to log like click.exceptions.UsageError
if not issubclass(type(e), click.exceptions.ClickException):
logger.error(traceback)
if cli.config.DEBUG_MODE:
cli.tools.terminal.echo(f'[R0b]{traceback}[X]')
elif e.args: # Will echo only if error have message
cli.tools.terminal.echo(f'[R0b]{e}[X]')
cli.tools.terminal.echo('')
sys.exit(1)
if __name__ == '__main__':
safe_tgbox_cli_startup()