Skip to content

Commit

Permalink
Merge pull request #22 from elkinaguas/add/allow_arguments_in_commands
Browse files Browse the repository at this point in the history
Add/allow arguments in commands
  • Loading branch information
elkinaguas authored Dec 18, 2023
2 parents 0eac421 + 8a70ddd commit f0c5c7a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
34 changes: 31 additions & 3 deletions clir/utils/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -98,8 +99,9 @@ def run_command(self):
if current_commands[c]["uid"] == uid:
command = c

if uid:
print(f'Running command: {command}')
command = _replace_arguments(command)
if uid and command:
print(f'[bold green]Running command:[/bold green] {command}')
os.system(command)

def copy_command(self):
Expand Down Expand Up @@ -253,4 +255,30 @@ def _get_commands(tag: str = "", grep: str = ""):

sorted_commands = dict(sorted(current_commands.items(), key=lambda item: item[1]["tag"]))

return sorted_commands
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)

# 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}

# Split the command into a list
command_list = command.split(" ")

# Replace arguments in the command
for arg, value in replacements.items():
for indx,term in enumerate(command_list):
if arg == term:
command_list[indx] = value

return " ".join(command_list)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
license = "MIT License"
Expand Down

0 comments on commit f0c5c7a

Please sign in to comment.