| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,6 +29,14 @@ def get_commands(): | |||
| 29 | 29 | ||
| 30 | 30 | @app.get("/command") | |
| 31 | 31 | 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 | + | ||
| 32 | 40 | if search: | |
| 33 | 41 | result = [ | |
| 34 | 42 | item | |
@@ -42,24 +50,59 @@ def get_commands(search: str = None): | |||
| 42 | 50 | ||
| 43 | 51 | @app.post("/command") | |
| 44 | 52 | 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 | + | ||
| 45 | 61 | Command.new(**command.dict()) | |
| 46 | 62 | return JSONResponse({"msg": "Command created"}, status_code=200) | |
| 47 | 63 | ||
| 48 | 64 | ||
| 49 | 65 | @app.patch("/command") | |
| 50 | 66 | 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 | + | ||
| 51 | 77 | Command.edit(old_title, command.dict()) | |
| 52 | 78 | return JSONResponse({"msg": "Command edited"}, status_code=200) | |
| 53 | 79 | ||
| 54 | 80 | ||
| 55 | 81 | @app.delete("/command") | |
| 56 | 82 | 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 | + | ||
| 57 | 91 | Command.remove(command.dict()) | |
| 58 | 92 | return JSONResponse({"msg": "Command removed"}, status_code=200) | |
| 59 | 93 | ||
| 60 | 94 | ||
| 61 | 95 | @app.get("/test-command") | |
| 62 | 96 | 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 | + | ||
| 63 | 106 | response, status = Command.test("lenovo", trigger) | |
| 64 | 107 | if status == 200: | |
| 65 | 108 | message = response.get('message') | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -66,7 +66,6 @@ def remove(): | |||
| 66 | 66 | message = f"\n[green]Success![/] Command `{selected['trigger']}` removed." | |
| 67 | 67 | ||
| 68 | 68 | if CommandWizard.confirm("Are you sure you want remove this command?"): | |
| 69 | - | ||
| 70 | 69 | with console.status("[yellow]Please wait...[/]"): | |
| 71 | 70 | time.sleep(5) | |
| 72 | 71 | Command.remove(selected) | |
@@ -77,7 +76,6 @@ def remove(): | |||
| 77 | 76 | ||
| 78 | 77 | @command_app.command(help="List all commands.") | |
| 79 | 78 | def list(): | |
| 80 | - | ||
| 81 | 79 | data = functions.load_json_file() | |
| 82 | 80 | ||
| 83 | 81 | table = Table(title="Command List", title_justify="center") | |
@@ -104,6 +102,13 @@ def list(): | |||
| 104 | 102 | ||
| 105 | 103 | @command_app.command(help="Test a commands.") | |
| 106 | 104 | 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 | + | ||
| 107 | 112 | console.rule("Test a command") | |
| 108 | 113 | ||
| 109 | 114 | if not trigger: | |
@@ -157,8 +162,16 @@ def run(): | |||
| 157 | 162 | console.rule("Running") | |
| 158 | 163 | TriggerCMDAgent.run() | |
| 159 | 164 | ||
| 165 | + | ||
| 160 | 166 | @command_app.command(help="Run TriggerCMD Desktop App") | |
| 161 | 167 | 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 | + | ||
| 162 | 175 | try: | |
| 163 | 176 | console.rule("Running UI") | |
| 164 | 177 | console.print("Type Ctrl+C to exit...") | |
| Back | FazBrowse Home | New Git URL |
0 commit comments