From 3e662fc3394e795392eae19b441da730074fab66 Mon Sep 17 00:00:00 2001 From: davi Date: Sat, 22 Oct 2022 12:32:15 -0300 Subject: [PATCH] docstring in some functions --- triggercmd_cli/api/main.py | 43 +++++++++++++++++++++++++++++++ triggercmd_cli/command/command.py | 17 ++++++++++-- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/triggercmd_cli/api/main.py b/triggercmd_cli/api/main.py index ba06d72..0026cd3 100644 --- a/triggercmd_cli/api/main.py +++ b/triggercmd_cli/api/main.py @@ -29,6 +29,14 @@ def get_commands(): @app.get("/command") def get_commands(search: str = None): + """ + It returns a list of commands that match the search term + + :param search: str = None + :type search: str + :return: A JSONResponse object with the data from the command file. + """ + if search: result = [ item @@ -42,24 +50,59 @@ def get_commands(search: str = None): @app.post("/command") def create_command(command: CommandSchema): + """ + Create a new command + + :param command: CommandSchema + :type command: CommandSchema + :return: A JSONResponse object with a message and a status code. + """ + Command.new(**command.dict()) return JSONResponse({"msg": "Command created"}, status_code=200) @app.patch("/command") def edit_command(old_title: str, command: CommandSchema): + """ + It takes a string and a CommandSchema object, and then edits the command with the old title to the new command + + :param old_title: The title of the command you want to edit + :type old_title: str + :param command: CommandSchema - This is the new command that will be used to replace the old one + :type command: CommandSchema + :return: A JSONResponse object with a message and a status code. + """ + Command.edit(old_title, command.dict()) return JSONResponse({"msg": "Command edited"}, status_code=200) @app.delete("/command") def delete_command(command: CommandSchema): + """ + It deletes a command from the database + + :param command: CommandSchema - this is the parameter that will be passed to the function + :type command: CommandSchema + :return: A JSONResponse object with a message and a status code. + """ + Command.remove(command.dict()) return JSONResponse({"msg": "Command removed"}, status_code=200) @app.get("/test-command") def test_command(trigger: str): + """ + It takes a trigger as a parameter, calls the test function in the Command class, and returns a JSON response with the + message and status code + + :param trigger: The trigger word for the command + :type trigger: str + :return: A JSONResponse object with a dictionary containing a key "msg" and a value of the message variable. + """ + response, status = Command.test("lenovo", trigger) if status == 200: message = response.get('message') diff --git a/triggercmd_cli/command/command.py b/triggercmd_cli/command/command.py index 6e23c5f..da924d0 100644 --- a/triggercmd_cli/command/command.py +++ b/triggercmd_cli/command/command.py @@ -66,7 +66,6 @@ def remove(): message = f"\n[green]Success![/] Command `{selected['trigger']}` removed." if CommandWizard.confirm("Are you sure you want remove this command?"): - with console.status("[yellow]Please wait...[/]"): time.sleep(5) Command.remove(selected) @@ -77,7 +76,6 @@ def remove(): @command_app.command(help="List all commands.") def list(): - data = functions.load_json_file() table = Table(title="Command List", title_justify="center") @@ -104,6 +102,13 @@ def list(): @command_app.command(help="Test a commands.") def test(trigger: str = typer.Option("", help="Trigger name")): + """ + It tests a command + + :param trigger: str = typer.Option("", help="Trigger name") + :type trigger: str + """ + console.rule("Test a command") if not trigger: @@ -157,8 +162,16 @@ def run(): console.rule("Running") TriggerCMDAgent.run() + @command_app.command(help="Run TriggerCMD Desktop App") def app(background: bool = False): + """ + This function runs the UI + + :param background: bool = False, defaults to False + :type background: bool (optional) + """ + try: console.rule("Running UI") console.print("Type Ctrl+C to exit...")