Skip to content

Commit

Permalink
Bring back the good part of fe4fd3a
Browse files Browse the repository at this point in the history
  • Loading branch information
themylogin committed Jan 14, 2025
1 parent 4329c87 commit 2257100
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions ixdiagnose/utils/command.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import subprocess

from typing import Optional, Union
from typing import Any, Optional, Union

from .run import run

Expand All @@ -14,12 +13,14 @@ def __init__(
self.command: Union[str, list] = command
self.description: str = description
self.env: Optional[dict] = env
self.max_length: Optional[int] = max_lines
self.max_lines: Optional[int] = max_lines
self.serializable: bool = serializable
self.safe_returncodes: list = safe_returncodes or [0]
self.execution_context: Any = None

def execute(self) -> subprocess.CompletedProcess:
cp = run(self.command, check=False, env=self.env)
if self.max_length and cp.returncode in self.safe_returncodes:
cp.stdout = cp.stdout.splitlines()[:self.max_length]
if cp.returncode in self.safe_returncodes:
if self.max_lines:
cp.stdout = "\n".join(cp.stdout.splitlines()[:self.max_lines])
return cp

0 comments on commit 2257100

Please sign in to comment.