From c236facb4d4c277773c83f1a4ee85b48833d7e67 Mon Sep 17 00:00:00 2001 From: Joris Date: Sat, 16 Sep 2023 18:28:54 +0200 Subject: Add CLI command to insert book in library --- src/main.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/main.py') diff --git a/src/main.py b/src/main.py index 618cc5a..1f07785 100644 --- a/src/main.py +++ b/src/main.py @@ -12,10 +12,15 @@ import os import library.command import view.command +import new.command def print_help(title='Manage book library'): print(f"""{title} +- Insert book entry with optional ebook file: + + $ python {sys.argv[0]} new [path-to-book] + - Print library metadata as json: $ python {sys.argv[0]} library @@ -38,6 +43,16 @@ def get_book_library(): def main(): match sys.argv: + case [ _, 'new' ]: + book_library = get_book_library() + new.command.run(book_library) + case [ _, 'new', book_source ]: + if os.path.isfile(book_source): + book_library = get_book_library() + new.command.run(book_library, book_source) + else: + print_help(title=f'File not found: {book_source}.') + exit(1) case [ _, 'library' ]: book_library = get_book_library() library.command.run(book_library) -- cgit v1.2.3