Skip to content

Commit 54089d1

Browse files
authored
Merge pull request #8 from davnunes/main
docstring in some functions
2 parents d8094bf + 3e662fc commit 54089d1

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

triggercmd_cli/api/main.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ def get_commands():
2929

3030
@app.get("/command")
3131
def get_commands(search: str = None):
32+
"""
33+
It returns a list of commands that match the search term
34+
35+
:param search: str = None
36+
:type search: str
37+
:return: A JSONResponse object with the data from the command file.
38+
"""
39+
3240
if search:
3341
result = [
3442
item
@@ -42,24 +50,59 @@ def get_commands(search: str = None):
4250

4351
@app.post("/command")
4452
def create_command(command: CommandSchema):
53+
"""
54+
Create a new command
55+
56+
:param command: CommandSchema
57+
:type command: CommandSchema
58+
:return: A JSONResponse object with a message and a status code.
59+
"""
60+
4561
Command.new(**command.dict())
4662
return JSONResponse({"msg": "Command created"}, status_code=200)
4763

4864

4965
@app.patch("/command")
5066
def edit_command(old_title: str, command: CommandSchema):
67+
"""
68+
It takes a string and a CommandSchema object, and then edits the command with the old title to the new command
69+
70+
:param old_title: The title of the command you want to edit
71+
:type old_title: str
72+
:param command: CommandSchema - This is the new command that will be used to replace the old one
73+
:type command: CommandSchema
74+
:return: A JSONResponse object with a message and a status code.
75+
"""
76+
5177
Command.edit(old_title, command.dict())
5278
return JSONResponse({"msg": "Command edited"}, status_code=200)
5379

5480

5581
@app.delete("/command")
5682
def delete_command(command: CommandSchema):
83+
"""
84+
It deletes a command from the database
85+
86+
:param command: CommandSchema - this is the parameter that will be passed to the function
87+
:type command: CommandSchema
88+
:return: A JSONResponse object with a message and a status code.
89+
"""
90+
5791
Command.remove(command.dict())
5892
return JSONResponse({"msg": "Command removed"}, status_code=200)
5993

6094

6195
@app.get("/test-command")
6296
def test_command(trigger: str):
97+
"""
98+
It takes a trigger as a parameter, calls the test function in the Command class, and returns a JSON response with the
99+
message and status code
100+
101+
:param trigger: The trigger word for the command
102+
:type trigger: str
103+
:return: A JSONResponse object with a dictionary containing a key "msg" and a value of the message variable.
104+
"""
105+
63106
response, status = Command.test("lenovo", trigger)
64107
if status == 200:
65108
message = response.get('message')

triggercmd_cli/command/command.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ def remove():
6666
message = f"\n[green]Success![/] Command `{selected['trigger']}` removed."
6767

6868
if CommandWizard.confirm("Are you sure you want remove this command?"):
69-
7069
with console.status("[yellow]Please wait...[/]"):
7170
time.sleep(5)
7271
Command.remove(selected)
@@ -77,7 +76,6 @@ def remove():
7776

7877
@command_app.command(help="List all commands.")
7978
def list():
80-
8179
data = functions.load_json_file()
8280

8381
table = Table(title="Command List", title_justify="center")
@@ -104,6 +102,13 @@ def list():
104102

105103
@command_app.command(help="Test a commands.")
106104
def test(trigger: str = typer.Option("", help="Trigger name")):
105+
"""
106+
It tests a command
107+
108+
:param trigger: str = typer.Option("", help="Trigger name")
109+
:type trigger: str
110+
"""
111+
107112
console.rule("Test a command")
108113

109114
if not trigger:
@@ -157,8 +162,16 @@ def run():
157162
console.rule("Running")
158163
TriggerCMDAgent.run()
159164

165+
160166
@command_app.command(help="Run TriggerCMD Desktop App")
161167
def app(background: bool = False):
168+
"""
169+
This function runs the UI
170+
171+
:param background: bool = False, defaults to False
172+
:type background: bool (optional)
173+
"""
174+
162175
try:
163176
console.rule("Running UI")
164177
console.print("Type Ctrl+C to exit...")

0 commit comments

Comments
 (0)