1717
1818import contextlib
1919import functools
20+ import shutil
2021import threading
2122from collections import defaultdict
2223from pathlib import Path
@@ -455,6 +456,13 @@ def require_clean(self) -> "Command":
455456
456457 return RequireClean (self )
457458
459+ @check_finalized
460+ def require_login (self ) -> "Command" :
461+ """Check that the user is logged in."""
462+ from renku .command .command_builder .repo import RequireLogin
463+
464+ return RequireLogin (self )
465+
458466 @check_finalized
459467 def with_communicator (self , communicator : CommunicationCallback ) -> "Command" :
460468 """Create a communicator.
@@ -479,6 +487,20 @@ def with_database(self, write: bool = False, path: Optional[str] = None, create:
479487
480488 return DatabaseCommand (self , write , path , create )
481489
490+ @check_finalized
491+ def with_gitlab_api (self ) -> "Command" :
492+ """Inject gitlab api client."""
493+ from renku .command .command_builder .gitlab import GitlabApiCommand
494+
495+ return GitlabApiCommand (self )
496+
497+ @check_finalized
498+ def with_storage_api (self ) -> "Command" :
499+ """Inject storage api client."""
500+ from renku .command .command_builder .storage import StorageApiCommand
501+
502+ return StorageApiCommand (self )
503+
482504
483505class CommandResult :
484506 """The result of a command.
@@ -496,3 +518,26 @@ def __init__(self, output, error, status) -> None:
496518 self .output = output
497519 self .error = error
498520 self .status = status
521+
522+
523+ class RequireExecutable (Command ):
524+ """Builder to check if an executable is installed."""
525+
526+ HOOK_ORDER = 4
527+
528+ def __init__ (self , builder : Command , executable : str ) -> None :
529+ """__init__ of RequireExecutable."""
530+ self ._builder = builder
531+ self ._executable = executable
532+
533+ def _pre_hook (self , builder : Command , context : dict , * args , ** kwargs ) -> None :
534+ """Check if an executable exists on the system.
535+
536+ Args:
537+ builder(Command): Current ``CommandBuilder``.
538+ context(dict): Current context.
539+ """
540+ if not shutil .which (self ._executable ):
541+ raise errors .ExecutableNotFound (
542+ f"Couldn't find the executable '{ self ._executable } ' on this system. Please make sure it's installed"
543+ )
0 commit comments