Skip to content

Commit

Permalink
refactor: no execute validation if are no commands added
Browse files Browse the repository at this point in the history
* fix: no sent CommandError when DISTRO_EXTRA_COMMANDS is no sent in the config.yml
  • Loading branch information
bra-i-am committed Apr 4, 2024
1 parent 1b069f9 commit c473596
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Distro command runner.
"""
# Was necessary to use this for compatibility with Python 3.8
from typing import List
from typing import List, Optional

from tutordistro.distro.extra_commands.domain.command_manager import CommandManager

Expand All @@ -18,9 +18,11 @@ class CommandsRunner:
commands_manager (ThemeRepository): The command manager to use for executing the extra command.
"""

def __init__(self, commands_manager: CommandManager, commands: List[str]):
def __init__(self, commands_manager: CommandManager, commands: Optional[List[str]]):
self.commands_manager = commands_manager
commands_manager.validate_commands(commands)

if commands is not None:
commands_manager.validate_commands(commands)

def __call__(self, command: str):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import subprocess
# Was necessary to use this for compatibility with Python 3.8
from typing import List, Optional
from typing import List

from tutordistro.distro.extra_commands.domain.command_manager import CommandManager
from tutordistro.distro.share.domain.command_error import CommandError
Expand All @@ -22,19 +22,14 @@ class TutorCommandManager(CommandManager):
CommandManager (class): Base command manager class.
"""

def validate_commands(self, commands: Optional[List[str]]):
def validate_commands(self, commands: List[str]):
"""
Takes all the extra commands sent through config.yml and verifies that
all the commands are correct before executing them
Args:
commands (list[str] | None): The commands sent through DISTRO_EXTRA_COMMANDS in config.yml
"""
if not commands:
raise CommandError(
"No commands found in the DISTRO_EXTRA_COMMANDS attribute of the config.yml file."
)

splitted_commands = [
split_string(command, COMMAND_CHAINING_OPERATORS) for command in commands
]
Expand Down

0 comments on commit c473596

Please sign in to comment.