From 5323953f9400dbc4caf6cfa8da0a9596be21fa14 Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Fri, 4 Oct 2024 21:33:46 -0700 Subject: [PATCH] handle Ctrl+C more gracefully --- archivebox/cli/__init__.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/archivebox/cli/__init__.py b/archivebox/cli/__init__.py index c3332abb..1ac7a9f9 100644 --- a/archivebox/cli/__init__.py +++ b/archivebox/cli/__init__.py @@ -1,15 +1,15 @@ __package__ = 'archivebox.cli' __command__ = 'archivebox' -import os import sys import argparse import threading -import tempfile from time import sleep from collections.abc import Mapping +from rich import print + from typing import Optional, List, IO, Union, Iterable from pathlib import Path @@ -242,8 +242,11 @@ def main(args: List[str] | Omitted=OMITTED, stdin: IO | Omitted=OMITTED, pwd: st stdin=stdin or None, ) - run_subcommand( - subcommand=command.subcommand, - subcommand_args=command.subcommand_args, - stdin=stdin or None, - ) + try: + run_subcommand( + subcommand=command.subcommand, + subcommand_args=command.subcommand_args, + stdin=stdin or None, + ) + except KeyboardInterrupt: + print('\n\n[red][X] Got CTRL+C. Exiting...[/red]')