
    h              	           S SK r S SKrS SKrS SKrS SKJrJrJrJr  SSK	J
r
  SSKJr  S\S\\   4S jrS\\   S\4S	 jrSS
S.S\\\\   4   S\\   S\S\R"                  4S jjrg)    N)AnyListOptionalUnion   )
is_windows)Errorscommandreturnc                 >    [         R                  " U [        (       + S9$ )zSplit a string command using shlex. Handles platform compatibility.

command (str) : The command to split
RETURNS (List[str]): The split command.
)posix)shlexsplitr   r
   s    N/home/james-whalen/.local/lib/python3.13/site-packages/weasel/util/commands.pysplit_commandr      s     ;;w*n55    c                 2    SR                  S U  5       5      $ )zJoin a command using shlex. shlex.join is only available for Python 3.8+,
so we're using a workaround here.

command (List[str]): The command to join.
RETURNS (str): The joined command
 c              3   N   #    U  H  n[         R                  " U5      v   M     g 7f)N)r   quote).0cmds     r   	<genexpr>join_command.<locals>.<genexpr>   s     8EKK$$s   #%)joinr   s    r   join_commandr      s     888888r   F)stdincapturer   r   c          
         [        U [        5      (       a  [        U 5      nU nOU nSR                  U 5      n [        R
                  " U[        R                  R                  5       USSU(       a  [        R                  OSU(       a  [        R                  OSS9nUR                  S:w  ac  U(       a\  SU S	3nUS
UR                   3-  nUR                   b  US-  nXeR                   -  n[        R"                  " U5      nXWl        XGl        UeUR                  S:w  a   [(        R*                  " UR                  5        U$ ! [         a+    [        [        R                  R                  XCS   S95      Sef = f)a  Run a command on the command line as a subprocess. If the subprocess
returns a non-zero exit code, a system exit is performed.

command (str / List[str]): The command. If provided as a string, the
    string will be split using shlex.split.
stdin (Optional[Any]): stdin to read from or None.
capture (bool): Whether to capture the output and errors. If False,
    the stdout and stderr will not be redirected, and if there's an error,
    sys.exit will be called with the return code. You should use capture=False
    when you want to turn over execution to the command, and capture=True
    when you want to run the command more like a function.
RETURNS (Optional[CompletedProcess]): The process object.
r   utf8FN)envinputencodingcheckstdoutstderrr   )str_commandtoolzError running command:

z

zSubprocess exited with status z$

Process log (stdout and stderr):

)
isinstancestrr   r   
subprocessrunosenvironcopyPIPESTDOUTFileNotFoundErrorr	   E501format
returncoder&   SubprocessErrorretr
   sysexit)r
   r   r   cmd_listcmd_strr8   messageerrors           r   run_commandr?      sJ   & '3 )((7#nn

!&-:??4(/:$$T
 ~~w.wit<3CNN3CDD::!AAGzz!G**73		1	 J%    KK7!E
	s   A$E 5E6)r.   r   r,   r9   typingr   r   r   r   compatr   errorsr	   r+   r   r   boolCompletedProcessr?    r   r   <module>rF      s    	   
 - -  63 649 69$s) 9 9  	53S	>"5 C=5 	5
   5r   