From df7a078954507507511263bafe8a4fe113211076 Mon Sep 17 00:00:00 2001 From: Wenzhe Xue Date: Fri, 9 Feb 2024 15:20:41 -0800 Subject: [PATCH] wip add cli log10 feedback or log10 feedback-task create --- log10/__main__.py | 32 ++++++++++++++++++++++++++++++++ log10/feedback/feedback.py | 15 +++++++++------ log10/feedback/feedback_task.py | 15 +++++++++------ pyproject.toml | 3 +++ 4 files changed, 53 insertions(+), 12 deletions(-) create mode 100644 log10/__main__.py diff --git a/log10/__main__.py b/log10/__main__.py new file mode 100644 index 00000000..52cf4a1c --- /dev/null +++ b/log10/__main__.py @@ -0,0 +1,32 @@ +import click + +from log10.feedback.feedback import create_feedback +from log10.feedback.feedback_task import create_feedback_task + + +@click.group() +def cli(): + pass + + +@click.group() +def feedback(): + pass + + +@click.group() +def feedback_task(): + pass + + +cli.add_command(feedback) +feedback.add_command(create_feedback, "create") +cli.add_command(feedback_task) +feedback_task.add_command(create_feedback_task, "create") + +if __name__ == "__main__": + cli() + + +# cli.add_command(feedback.create_feedback) +# cli.add_command(feedback_task.create_feedback_task) diff --git a/log10/feedback/feedback.py b/log10/feedback/feedback.py index 87458656..70e8844c 100644 --- a/log10/feedback/feedback.py +++ b/log10/feedback/feedback.py @@ -1,6 +1,6 @@ -import click import logging +import click import httpx from dotenv import load_dotenv @@ -57,9 +57,12 @@ def create(self, task_id: str, rate: dict) -> httpx.Response: return res @click.command() -@click.option("--task_id", help="Task ID") -@click.option("--rate", help="Rate in JSON format") +@click.option("--task_id", prompt="Enter task id", help="Task ID") +@click.option("--rate", prompt="Enter task rate", help="Rate in JSON format") def create_feedback(task_id, rate): - fb = Feedback() - feedback = fb.create(task_id=task_id, rate=rate) - print(feedback) + click.echo("Creating feedback") + click.echo(f"Task ID: {task_id}") + click.echo(f"Rate: {rate}") + # fb = Feedback() + # feedback = fb.create(task_id=task_id, rate=rate) + # click.echo(feedback) diff --git a/log10/feedback/feedback_task.py b/log10/feedback/feedback_task.py index 41eed5c0..d81a5996 100644 --- a/log10/feedback/feedback_task.py +++ b/log10/feedback/feedback_task.py @@ -1,6 +1,6 @@ -import click import logging +import click import httpx from dotenv import load_dotenv @@ -47,9 +47,12 @@ def create(self, name: str, task_schema: dict) -> httpx.Response: # create a cli interface for FeebackTask.create function @click.command() -@click.option("--name", help="Name of the task") -@click.option("--task_schema", help="Task schema") +@click.option("--name", prompt="Enter feedback task name", help="Name of the task") +@click.option("--task_schema", prompt="Enter feedback task schema", help="Task schema") def create_feedback_task(name, task_schema): - fb_task = FeedbackTask() - task = fb_task.create(name=name, task_schema=task_schema) - print(task) + click.echo("Creating feedback task") + click.echo(f"Name: {name}") + click.echo(f"Task Schema: {task_schema}") + # fb_task = FeedbackTask() + # task = fb_task.create(name=name, task_schema=task_schema) + # click.echo(task) diff --git a/pyproject.toml b/pyproject.toml index c953fe35..b7bd4f85 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,6 +19,9 @@ packages = [ { include = "log10" }, ] +[tool.poetry.scripts] +log10 = "log10.__main__:cli" + [tool.poetry.group.dev.dependencies] build = "^0.10.0" pytest = "^8.0.0"