|
| 1 | +import logging |
| 2 | +import sys |
| 3 | + |
| 4 | +import click |
| 5 | +from rich import box, console, traceback |
| 6 | +from rich.table import Table |
| 7 | + |
| 8 | +import waveform_editor |
| 9 | + |
| 10 | +logger = logging.getLogger(__name__) |
| 11 | + |
| 12 | + |
| 13 | +def _excepthook(type_, value, tb): |
| 14 | + logger.debug("Suppressed traceback:", exc_info=(type_, value, tb)) |
| 15 | + # Only display the last traceback frame: |
| 16 | + if tb is not None: |
| 17 | + while tb.tb_next: |
| 18 | + tb = tb.tb_next |
| 19 | + rich_tb = traceback.Traceback.from_exception(type_, value, tb, extra_lines=0) |
| 20 | + console.Console(stderr=True).print(rich_tb) |
| 21 | + |
| 22 | + |
| 23 | +@click.group("waveform-editor", invoke_without_command=True, no_args_is_help=True) |
| 24 | +@click.option("-v", "--version", is_flag=True, help="Show version information") |
| 25 | +def cli(version): |
| 26 | + """The Waveform Editor command line interface. |
| 27 | +
|
| 28 | + Please use one of the available commands listed below. You can get help for each |
| 29 | + command by executing: |
| 30 | +
|
| 31 | + waveform-editor <command> --help |
| 32 | + """ |
| 33 | + # Limit the traceback to 1 item: avoid scaring CLI users with long traceback prints |
| 34 | + # and let them focus on the actual error message |
| 35 | + sys.excepthook = _excepthook |
| 36 | + |
| 37 | + if version: |
| 38 | + print_version() |
| 39 | + |
| 40 | + |
| 41 | +def print_version(): |
| 42 | + """Print version information of the waveform editor.""" |
| 43 | + cons = console.Console() |
| 44 | + grid = Table( |
| 45 | + title="waveform editor version info", show_header=False, title_style="bold" |
| 46 | + ) |
| 47 | + grid.box = box.HORIZONTALS |
| 48 | + if cons.size.width > 120: |
| 49 | + grid.width = 120 |
| 50 | + grid.add_row("waveform editor version:", waveform_editor.__version__) |
| 51 | + grid.add_section() |
| 52 | + console.Console().print(grid) |
| 53 | + |
| 54 | + |
| 55 | +if __name__ == "__main__": |
| 56 | + cli() |
0 commit comments