From anonymous, 2 Weeks ago, written in Python.
Embed
  1. import pathlib
  2. import subprocess
  3. from typing import Literal, overload
  4.  
  5.  
  6. class Tool:
  7.  
  8.     def __init__(self, path: pathlib.Path) -> None:
  9.         self.path = path
  10.  
  11.     @staticmethod
  12.     @overload
  13.     def _run(
  14.         *args: str | pathlib.Path,
  15.         cwd: pathlib.Path,
  16.         capture_output: bool = ...,
  17.         check: bool = ...,
  18.         text: Literal[True] = ...,
  19.     ) -> subprocess.CompletedProcess[str]:
  20.         ...
  21.  
  22.     @staticmethod
  23.     @overload
  24.     def _run(
  25.         *args: str | pathlib.Path,
  26.         cwd: pathlib.Path,
  27.         capture_output: bool = ...,
  28.         check: bool = ...,
  29.         text: Literal[False],
  30.     ) -> subprocess.CompletedProcess[bytes]:
  31.         ...
  32.  
  33.     @staticmethod
  34.     @overload
  35.     def _run(
  36.         *args: str | pathlib.Path,
  37.         cwd: pathlib.Path,
  38.         capture_output: bool = ...,
  39.         check: bool = ...,
  40.         text: bool = ...,
  41.     ) -> subprocess.CompletedProcess[str] | subprocess.CompletedProcess[bytes]:
  42.         ...
  43.  
  44.     @staticmethod
  45.     def _run(
  46.         *args: str | pathlib.Path,
  47.         cwd: pathlib.Path,
  48.         capture_output: bool = True,
  49.         check: bool = True,
  50.         text: bool = True,
  51.     ) -> subprocess.CompletedProcess[str] | subprocess.CompletedProcess[bytes]:
  52.         # actually does some more work with error handling and such
  53.         return subprocess.run(
  54.             ["..."] + list(args),
  55.             cwd=cwd,
  56.             text=text,
  57.             capture_output=capture_output,
  58.             check=check,
  59.         )
  60.  
  61.     @overload
  62.     def run(
  63.         self,
  64.         *args: str | pathlib.Path,
  65.         capture_output: bool = ...,
  66.         check: bool = ...,
  67.         text: Literal[True] = ...,
  68.     ) -> subprocess.CompletedProcess[str]:
  69.         ...
  70.  
  71.     @overload
  72.     def run(
  73.         self,
  74.         *args: str | pathlib.Path,
  75.         capture_output: bool = ...,
  76.         check: bool = ...,
  77.         text: Literal[False],
  78.     ) -> subprocess.CompletedProcess[bytes]:
  79.         ...
  80.  
  81.     @overload
  82.     def run(
  83.         self,
  84.         *args: str | pathlib.Path,
  85.         capture_output: bool = ...,
  86.         check: bool = ...,
  87.         text: bool = ...,
  88.     ) -> subprocess.CompletedProcess[str] | subprocess.CompletedProcess[bytes]:
  89.         ...
  90.  
  91.     def run(
  92.         self,
  93.         *args: str | pathlib.Path,
  94.         capture_output: bool = True,
  95.         check: bool = True,
  96.         text: bool = True,
  97.     ) -> subprocess.CompletedProcess[str] | subprocess.CompletedProcess[bytes]:
  98.         return Tool._run(
  99.             *args,
  100.             cwd=self.path,
  101.             capture_output=capture_output,
  102.             check=check,
  103.             text=text,
  104.         )