1313# limitations under the License.
1414
1515import os
16- import base64
1716import sys
1817import subprocess
1918from typing import List
2019from cortex .exceptions import CortexBinaryException
2120
22- MIXED_CORTEX_MARKER = "~~cortex~~"
23-
2421
2522def run ():
2623 """
@@ -36,21 +33,19 @@ def run():
3633def run_cli (
3734 args : List [str ],
3835 hide_output : bool = False ,
39- mixed_output : bool = False ,
4036) -> str :
4137 """
4238 Runs the Cortex binary with the specified arguments.
4339
4440 Args:
4541 args: Arguments to use when invoking the Cortex CLI.
4642 hide_output: Flag to prevent streaming CLI output to stdout.
47- mixed_output: Used to handle CLI output that both prints to stdout and should be returned.
4843
4944 Raises:
5045 CortexBinaryException: Cortex CLI command returned an error.
5146
5247 Returns:
53- The stdout from the Cortex CLI command, or the result if mixed_output output .
48+ The stdout from the Cortex CLI command.
5449 """
5550
5651 env = os .environ .copy ()
@@ -71,35 +66,16 @@ def run_cli(
7166 for c in iter (lambda : process .stdout .read (1 ), "" ):
7267 output += c
7368
74- if mixed_output :
75- if output [- 2 :] == "\n ~" or output == "~" :
76- processing_result = True
77- output = output [:- 1 ]
78- if processing_result :
79- result += c
80- if (
81- result [: len (MIXED_CORTEX_MARKER )] == MIXED_CORTEX_MARKER
82- and result [- len (MIXED_CORTEX_MARKER ) :] == MIXED_CORTEX_MARKER
83- and len (result ) > len (MIXED_CORTEX_MARKER )
84- ):
85- result = result [len (MIXED_CORTEX_MARKER ) : - len (MIXED_CORTEX_MARKER )]
86- result = base64 .b64decode (result ).decode ("utf8" )
87- processed_result = True
88-
89- output = output [:- 1 ]
9069 if not hide_output :
91- if (not mixed_output ) or (mixed_output and not processing_result ):
92- sys .stdout .write (c )
93- sys .stdout .flush ()
70+ sys .stdout .write (c )
71+ sys .stdout .flush ()
9472
9573 if processed_result == True :
9674 processing_result = False
9775
9876 process .wait ()
9977
10078 if process .returncode == 0 :
101- if mixed_output :
102- return result
10379 return output
10480
10581 if result != "" :
0 commit comments