From 24eb6e64ad9362c36431881c617a4102e9247da5 Mon Sep 17 00:00:00 2001 From: croketillo Date: Tue, 14 Nov 2023 21:44:39 +0100 Subject: [PATCH 1/3] adding check_config before executing 'NEW' command --- clir/cli.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/clir/cli.py b/clir/cli.py index a0c389b..3fb3bbb 100644 --- a/clir/cli.py +++ b/clir/cli.py @@ -1,5 +1,6 @@ import rich_click as click import os +import subprocess from rich.prompt import Prompt from clir.utils.objects import Command from clir.utils.objects import CommandTable @@ -8,6 +9,13 @@ def cli(): pass +def check_config(): + # Coloca el código de la función init aquí + dir_path = os.path.join(os.path.expanduser('~'), '.clir') + file_path = os.path.join(dir_path, 'commands.json') + + return os.path.exists(file_path) + #--------------------------------------- CLI commands ------------------------------------------------------- @cli.command(help="Clir initial configuration 🛠️") @@ -30,13 +38,23 @@ def init(): @cli.command(help="Save new command 💾") def new(): + if not check_config(): + print("Initial configuration is not set. Executing 'clir init'...") + subprocess.run(["clir", "init"]) + + # Check again after executing 'clir init' + if not check_config(): + print("Could not set the initial configuration. Unable to add the new command.") + return + command = Prompt.ask("Command") description = Prompt.ask("Description") tag = Prompt.ask("Tag") - new_command = Command(command = command, description = description, tag = tag) + new_command = Command(command=command, description=description, tag=tag) new_command.save_command() + @cli.command(help="Remove command 👋") @click.option('-t', '--tag', help="Search by tag") @click.option('-g', '--grep', help="Search by grep") From 2edc189aa34e5043b82e7201301772d93ed5c1c9 Mon Sep 17 00:00:00 2001 From: croketillo Date: Tue, 14 Nov 2023 21:49:52 +0100 Subject: [PATCH 2/3] Revert "adding check_config before executing 'NEW' command to MAIN branch" This reverts commit 24eb6e64ad9362c36431881c617a4102e9247da5. --- clir/cli.py | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/clir/cli.py b/clir/cli.py index 3fb3bbb..a0c389b 100644 --- a/clir/cli.py +++ b/clir/cli.py @@ -1,6 +1,5 @@ import rich_click as click import os -import subprocess from rich.prompt import Prompt from clir.utils.objects import Command from clir.utils.objects import CommandTable @@ -9,13 +8,6 @@ def cli(): pass -def check_config(): - # Coloca el código de la función init aquí - dir_path = os.path.join(os.path.expanduser('~'), '.clir') - file_path = os.path.join(dir_path, 'commands.json') - - return os.path.exists(file_path) - #--------------------------------------- CLI commands ------------------------------------------------------- @cli.command(help="Clir initial configuration 🛠️") @@ -38,23 +30,13 @@ def init(): @cli.command(help="Save new command 💾") def new(): - if not check_config(): - print("Initial configuration is not set. Executing 'clir init'...") - subprocess.run(["clir", "init"]) - - # Check again after executing 'clir init' - if not check_config(): - print("Could not set the initial configuration. Unable to add the new command.") - return - command = Prompt.ask("Command") description = Prompt.ask("Description") tag = Prompt.ask("Tag") - new_command = Command(command=command, description=description, tag=tag) + new_command = Command(command = command, description = description, tag = tag) new_command.save_command() - @cli.command(help="Remove command 👋") @click.option('-t', '--tag', help="Search by tag") @click.option('-g', '--grep', help="Search by grep") From b0f69a923c8fd851200451f05e3c35c71525a873 Mon Sep 17 00:00:00 2001 From: croketillo Date: Tue, 14 Nov 2023 21:56:07 +0100 Subject: [PATCH 3/3] adding check_config before executing NEW command --- clir/cli.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/clir/cli.py b/clir/cli.py index a0c389b..edb3a61 100644 --- a/clir/cli.py +++ b/clir/cli.py @@ -1,5 +1,6 @@ import rich_click as click import os +import subprocess from rich.prompt import Prompt from clir.utils.objects import Command from clir.utils.objects import CommandTable @@ -8,6 +9,11 @@ def cli(): pass +def check_config(): + dir_path = os.path.join(os.path.expanduser('~'), '.clir') + file_path = os.path.join(dir_path, 'commands.json') + + return os.path.exists(file_path) #--------------------------------------- CLI commands ------------------------------------------------------- @cli.command(help="Clir initial configuration 🛠️") @@ -30,6 +36,14 @@ def init(): @cli.command(help="Save new command 💾") def new(): + if not check_config(): + print("Initial configuration is not set. Executing 'clir init'...") + subprocess.run(["clir", "init"]) + + # Check again after executing 'clir init' + if not check_config(): + print("Could not set the initial configuration. Unable to add the new command.") + return command = Prompt.ask("Command") description = Prompt.ask("Description") tag = Prompt.ask("Tag")