From 0d192819409faf14415d3853c364509818524aa5 Mon Sep 17 00:00:00 2001 From: Elkin Aguas Date: Mon, 18 Dec 2023 19:36:48 +0100 Subject: [PATCH 1/4] Add arguments support --- clir/utils/objects.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/clir/utils/objects.py b/clir/utils/objects.py index 468f0f6..843be0c 100644 --- a/clir/utils/objects.py +++ b/clir/utils/objects.py @@ -98,6 +98,7 @@ def run_command(self): if current_commands[c]["uid"] == uid: command = c + command = _replace_arguments(command) if uid: print(f'Running command: {command}') os.system(command) @@ -253,4 +254,20 @@ def _get_commands(tag: str = "", grep: str = ""): sorted_commands = dict(sorted(current_commands.items(), key=lambda item: item[1]["tag"])) - return sorted_commands \ No newline at end of file + return sorted_commands + +def _get_user_input(arg): + return input(f"Enter value for '{arg}': ") + +def _replace_arguments(command): + # Use regex to find all arguments with underscores + matches = re.findall(r'_\w+', command) + + # Prompt the user for values for each argument + replacements = {arg: _get_user_input(arg) for arg in matches} + + # Replace arguments in the command + for arg, value in replacements.items(): + command = command.replace(arg, value) + + return command \ No newline at end of file From 76bafb01e1153ae7afffae2ff24e0e385b9e0564 Mon Sep 17 00:00:00 2001 From: Elkin Aguas Date: Mon, 18 Dec 2023 19:39:02 +0100 Subject: [PATCH 2/4] Update version to 0.5.0 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 8cd3d42..0f40099 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "clir" -version = "0.4.3" +version = "0.5.0" description = "A clear and fast way to store and recover your commands" authors = ["Elkin Aguas "] license = "MIT License" From 5c580affb20d492bb3182831495731c6119a47ff Mon Sep 17 00:00:00 2001 From: Elkin Aguas Date: Mon, 18 Dec 2023 19:58:10 +0100 Subject: [PATCH 3/4] Fix similar commands bug --- clir/utils/objects.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/clir/utils/objects.py b/clir/utils/objects.py index 843be0c..4509ab1 100644 --- a/clir/utils/objects.py +++ b/clir/utils/objects.py @@ -262,12 +262,20 @@ def _get_user_input(arg): def _replace_arguments(command): # Use regex to find all arguments with underscores matches = re.findall(r'_\w+', command) + + print(f"Found {matches} arguments") # Prompt the user for values for each argument replacements = {arg: _get_user_input(arg) for arg in matches} + + print(f"Replacing arguments with values: {replacements}") + command_list = command.split(" ") + # Replace arguments in the command for arg, value in replacements.items(): - command = command.replace(arg, value) + for indx,term in enumerate(command_list): + if arg == term: + command_list[indx] = value - return command \ No newline at end of file + return " ".join(command_list) \ No newline at end of file From 8a70ddd54fe4e09f0d59692501e60faea35a0bea Mon Sep 17 00:00:00 2001 From: Elkin Aguas Date: Mon, 18 Dec 2023 20:07:04 +0100 Subject: [PATCH 4/4] Add exception for repeated commands --- clir/utils/objects.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/clir/utils/objects.py b/clir/utils/objects.py index 4509ab1..2c55056 100644 --- a/clir/utils/objects.py +++ b/clir/utils/objects.py @@ -5,6 +5,7 @@ import platform import subprocess from rich import box +from rich import print from rich.console import Console from rich.table import Table from rich.prompt import Prompt @@ -99,8 +100,8 @@ def run_command(self): command = c command = _replace_arguments(command) - if uid: - print(f'Running command: {command}') + if uid and command: + print(f'[bold green]Running command:[/bold green] {command}') os.system(command) def copy_command(self): @@ -263,13 +264,15 @@ def _replace_arguments(command): # Use regex to find all arguments with underscores matches = re.findall(r'_\w+', command) - print(f"Found {matches} arguments") + # Check that all arguments are unique + if len(matches) != len(set(matches)): + print("[bold red]Make sure that all arguments are unique[/bold red]") + return None # Prompt the user for values for each argument replacements = {arg: _get_user_input(arg) for arg in matches} - - print(f"Replacing arguments with values: {replacements}") + # Split the command into a list command_list = command.split(" ") # Replace arguments in the command