diff --git a/elia_chat/__main__.py b/elia_chat/__main__.py index 9dd14af..723981b 100644 --- a/elia_chat/__main__.py +++ b/elia_chat/__main__.py @@ -2,10 +2,13 @@ Elia CLI """ +import pathlib + import click from elia_chat.app import app from elia_chat.database.create_database import create_database +from elia_chat.database.import_chatgpt import import_chatgpt_data from elia_chat.database.models import sqlite_file_name @@ -23,22 +26,36 @@ def cli(context: click.Context) -> None: app.run() -@cli.group() -def db() -> None: - """ - Elia database interactions - """ - - -@db.command() +@cli.command() def reset() -> None: """ Reset the database + + This command will delete the database file and recreate it. + Previously saved conversations and data will be lost. """ sqlite_file_name.unlink(missing_ok=True) create_database() click.echo(f"♻️ Database reset @ {sqlite_file_name}") +@cli.command("import") +@click.argument( + "file", + type=click.Path( + exists=True, dir_okay=False, path_type=pathlib.Path, resolve_path=True + ), +) +def import_file_to_db(file) -> None: + """ + Import ChatGPT Conversations + + This command will import the ChatGPT conversations from a local + JSON file into the database. + """ + import_chatgpt_data(file=file) + click.echo(f"✅ ChatGPT data imported into database {file}") + + if __name__ == "__main__": cli()