diff options
| author | Joris Guyonvarch | 2025-12-26 18:41:26 +0100 |
|---|---|---|
| committer | Joris Guyonvarch | 2025-12-27 20:41:44 +0100 |
| commit | a110c200e86d2325af07167531fac0f61d9681a0 (patch) | |
| tree | 90e843f915a2e153ba735849afd83710d90560bf /cli/main.py | |
| parent | a26d92ad5055fa057647158eb79511e7b1841162 (diff) | |
Switch to GUI to manage the library
Allow to regroup the CLI and the view into one unique tool.
Diffstat (limited to 'cli/main.py')
| -rw-r--r-- | cli/main.py | 80 |
1 files changed, 0 insertions, 80 deletions
diff --git a/cli/main.py b/cli/main.py deleted file mode 100644 index 01434fa..0000000 --- a/cli/main.py +++ /dev/null @@ -1,80 +0,0 @@ -# Manage book library. -# -# Required dependencies: -# -# - python >= 3.11 -# - requests -# - pillow -# - ebook-convert CLI (from calibre) - -import cli.library.command -import cli.new.command -import cli.view.command -import os -import sys - -def main(bin_dir): - match sys.argv: - case [ _, 'new' ]: - books_library = get_books_library() - cli.new.command.run(books_library) - case [ _, 'new', book_source ]: - if os.path.isfile(book_source): - books_library = get_books_library() - cli.new.command.run(books_library, book_source) - else: - print_help(title=f'File not found: {book_source}.') - exit(1) - case [ _, 'library' ]: - books_library = get_books_library() - cli.library.command.run(books_library) - case [ _, 'view' ]: - books_library = get_books_library() - books_browser = get_env_var('BOOKS_BROWSER') - cli.view.command.run(books_library, books_browser, bin_dir) - case [ _, '--help' ]: - print_help() - case [ _, '-h' ]: - print_help() - case _: - print_help('Command not found.') - exit(1) - -def get_books_library(): - books_library = get_env_var('BOOKS_LIBRARY') - if os.path.isdir(books_library): - return books_library - else: - print_help(title=f'BOOKS_LIBRARY {books_library} not found.') - exit(1) - -def get_env_var(key): - value = os.getenv(key) - if value: - return value - else: - print_help(title=f'{key} environment variable is required.') - exit(1) - -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 - -- View books in web page: - - $ python {sys.argv[0]} view - -Environment variables: - - BOOKS_LIBRARY: path to book library, - BOOKS_BROWSER: browser command executed to view the library.""") - -if __name__ == "__main__": - main() |
