Sfoglia il codice sorgente

refactor: log shell

Sam Jaffe 1 mese fa
parent
commit
1eca407199
1 ha cambiato i file con 9 aggiunte e 3 eliminazioni
  1. 9 3
      src/cipy/action.py

+ 9 - 3
src/cipy/action.py

@@ -5,7 +5,7 @@ import subprocess
 import tempfile
 
 from textwrap import dedent
-from typing import Any, final
+from typing import Any, ClassVar, final
 
 from colored import Fore, Style
 from pydantic import Field, PrivateAttr
@@ -15,7 +15,7 @@ from cipy.common import Action, Context, Factory, Ref, Results, Status, _validat
 from cipy.shell import Shell
 
 
-class Call(Action, extra='allow'):
+class Call(Action, extra="allow"):
     """
     A wrapper action that allows the passing in of computed arguments, equivalent
     to GitHub Actions' uses-with pattern. It is not necessary to use a Call Action
@@ -45,6 +45,7 @@ class Call(Action, extra='allow'):
             ref=cipy.Ref("inputs.target_branch")
         )
     """
+
     name: str = ""
     using: Action
     __pydantic_extra__: dict[str, bool | int | float | str | Ref | Factory]
@@ -104,6 +105,8 @@ class NodeScript(Action):
 class Script(Action):
     """Action descriptor for a generic shell runner"""
 
+    _GREEN: ClassVar[str] = Fore.dark_sea_green_4b + Style.BOLD
+
     shell: Shell = Shell.DEFAULT
     name: str = ""
     script: str
@@ -115,9 +118,12 @@ class Script(Action):
         if not self.name:
             self.name = self._lines[0]
 
+    def _shell_log(self) -> list[str]:
+        return ["shell: " + " ".join(self.shell.command("{0}"))]
+
     @final
     @cipy.runner.ipc
-    @cipy.runner.preamble(extra=[(f"{Fore.dark_sea_green_4b}{Style.BOLD}", lambda s: s._lines)])
+    @cipy.runner.preamble(extra=[(_GREEN, lambda s: s._lines), ("", _shell_log)])
     def run(self, context: Context) -> Status:
         with tempfile.NamedTemporaryFile(suffix=self.shell.extension()) as script:
             script.write(self.script.encode("utf-8"))