Skip to content

Commit

Permalink
Merge pull request #8 from davnunes/main
Browse files Browse the repository at this point in the history
docstring in some functions
  • Loading branch information
GussSoares committed Oct 22, 2022
2 parents d8094bf + 3e662fc commit 54089d1
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
43 changes: 43 additions & 0 deletions triggercmd_cli/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
Expand Down
17 changes: 15 additions & 2 deletions triggercmd_cli/command/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand All @@ -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:
Expand Down Expand Up @@ -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...")
Expand Down

0 comments on commit 54089d1

Please sign in to comment.