diff --git a/notification_client/cli.py b/notification_client/cli.py index 389e664..22657bc 100644 --- a/notification_client/cli.py +++ b/notification_client/cli.py @@ -39,6 +39,12 @@ def up( 5555, "--port", "-p", help="The server's port to notify [b]clients[/].", rich_help_panel="Connection", + ), + notification_dir: str = typer.Option( + None, "--notification-dir", "-d", + help="The client will save notifications to the directory by the path. Does not save if this option is not provided.", + rich_help_panel="Persistence", + show_default=False, ) ): """ @@ -46,7 +52,7 @@ def up( """ try: - client = Client(ip, port) + client = Client(ip, port, notification_dir) asyncio.run(client.connect()) except KeyboardInterrupt: MessagePrinter.bye() diff --git a/notification_client/client.py b/notification_client/client.py index c70f53f..829171d 100644 --- a/notification_client/client.py +++ b/notification_client/client.py @@ -29,9 +29,9 @@ from notification_client.notification_saver import NotificationSaver class Client: BUFFER_SIZE = 1024 - NOTIFICATION_DIR = 'notifications' + NOTIFICATION_DIR = None - def __init__(self, ip: str, port: int, notification_dir: str = 'notifications'): + def __init__(self, ip: str, port: int, notification_dir: str | None = None): self.__ip = ip self.__port = port self.NOTIFICATION_DIR = notification_dir @@ -65,7 +65,8 @@ class Client: Notification.notify(title, message) - NotificationSaver.save_notification(self.NOTIFICATION_DIR, title, message, now) + if not self.NOTIFICATION_DIR is None: + NotificationSaver.save_notification(self.NOTIFICATION_DIR, title, message, now) except asyncio.CancelledError: print('Something went wrong')