aboutsummaryrefslogtreecommitdiff
path: root/src/main.py
diff options
context:
space:
mode:
authorJoris2023-09-16 18:28:16 +0200
committerJoris2023-09-16 18:31:24 +0200
commit06f045e90bb57c36738e58ee6830e2a2391bc6a3 (patch)
treea5b65b048c103b4ea0e5d3c0fa5e115cbaf3cf5f /src/main.py
parent230f2e0623d22af6e68466884bd5dea5dcb846dc (diff)
Migrate CLI to python
Diffstat (limited to 'src/main.py')
-rw-r--r--src/main.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/main.py b/src/main.py
new file mode 100644
index 0000000..618cc5a
--- /dev/null
+++ b/src/main.py
@@ -0,0 +1,56 @@
+# Manage book library.
+#
+# Required dependencies:
+#
+# - python >= 3.11
+# - requests
+# - pillow
+# - ebook-convert CLI (from calibre)
+
+import sys
+import os
+
+import library.command
+import view.command
+
+def print_help(title='Manage book library'):
+ print(f"""{title}
+
+- Print library metadata as json:
+
+ $ python {sys.argv[0]} library
+
+- View books in web page:
+
+ $ python {sys.argv[0]} view browser-cmd
+
+Environment variables:
+
+ BOOK_LIBRARY: path to book library.""")
+
+def get_book_library():
+ path = os.getenv('BOOK_LIBRARY')
+ if path is None or not os.path.isdir(path):
+ print_help(title='BOOK_LIBRARY environment variable is required.')
+ exit(1)
+ else:
+ return path
+
+def main():
+ match sys.argv:
+ case [ _, 'library' ]:
+ book_library = get_book_library()
+ library.command.run(book_library)
+ case [ _, 'view', browser_cmd ]:
+ book_library = get_book_library()
+ view.command.run(book_library, browser_cmd)
+ case [ _, '--help' ]:
+ print_help()
+ case [ _, '-h' ]:
+ print_help()
+ case _:
+ print_help('Command not found.')
+ exit(1)
+
+if __name__ == "__main__":
+ main()