@@ -46,7 +46,7 @@ def validate_pod_name(name):
4646 to `command --arg=val`. If you want to use spaces instead, set this to ' '
4747"""
4848
49- import asyncio
49+ import asyncio . subprocess
5050import logging
5151import os
5252import subprocess
@@ -87,7 +87,7 @@ def from_dict(cls, arg_dict):
8787 transformer = arg_dict .get ("transformer" , None ),
8888 )
8989
90- def _to_dict (self ):
90+ def to_dict (self ):
9191 """
9292 Convert the Argument to a dictionary
9393 :return: the dictionary representation of the Argument
@@ -96,7 +96,7 @@ def _to_dict(self):
9696 return {
9797 "literal_name" : self .literal_name ,
9898 "default" : self .default ,
99- "validator" : self .validator ._to_dict () if self .validator is not None else None ,
99+ "validator" : self .validator .to_dict () if self .validator is not None else None ,
100100 }
101101
102102 def is_valid (self , value ):
@@ -139,7 +139,7 @@ def arg_converter(value: dict):
139139
140140
141141@define
142- class Command ( object ):
142+ class Command : # pylint: disable=too-many-instance-attributes
143143 """
144144 Command represents a command to be run with the cli_wrapper
145145 """
@@ -154,7 +154,7 @@ class Command(object):
154154 arg_separator : str = field (repr = False , default = "=" )
155155
156156 @classmethod
157- def _from_dict (cls , command_dict , ** kwargs ):
157+ def from_dict (cls , command_dict , ** kwargs ):
158158 """
159159 Create a Command from a dictionary
160160 :param command_dict: the dictionary to be converted
@@ -172,7 +172,7 @@ def _from_dict(cls, command_dict, **kwargs):
172172 ** kwargs ,
173173 )
174174
175- def _to_dict (self ):
175+ def to_dict (self ):
176176 """
177177 Convert the Command to a dictionary.
178178 Excludes prefixes/separators, because they are set in the CLIWrapper
@@ -182,8 +182,8 @@ def _to_dict(self):
182182 return {
183183 "cli_command" : self .cli_command ,
184184 "default_flags" : self .default_flags ,
185- "args" : {k : v ._to_dict () for k , v in self .args .items ()},
186- "parse" : self .parse ._to_dict () if self .parse is not None else None ,
185+ "args" : {k : v .to_dict () for k , v in self .args .items ()},
186+ "parse" : self .parse .to_dict () if self .parse is not None else None ,
187187 }
188188
189189 def validate_args (self , * args , ** kwargs ):
@@ -231,12 +231,13 @@ def build_args(self, *args, **kwargs):
231231
232232
233233@define
234- class CLIWrapper :
234+ class CLIWrapper : # pylint: disable=too-many-instance-attributes
235235 path : str
236236 env : dict [str , str ] = None
237237 commands : dict [str , Command ] = {}
238238
239239 trusting : bool = True
240+ raise_exc : bool = False
240241 async_ : bool = False
241242 default_transformer : str = "snake2kebab"
242243 short_prefix : str = "-"
@@ -263,17 +264,19 @@ def _get_command(self, command: str):
263264 return c
264265 return self .commands [command ]
265266
266- def _update_command (
267+ def _update_command ( # pylint: disable=too-many-arguments
267268 self ,
268269 command : str ,
269- cli_command : str = None ,
270+ * ,
271+ cli_command : str | list [str ] = None ,
270272 args : dict [str | int , any ] = None ,
271273 default_flags : dict = None ,
272274 parse = None ,
273275 ):
274276 """
275277 update the command to be run with the cli_wrapper
276- :param command: the subcommand for the cli tool
278+ :param command: the command name for the wrapper
279+ :param cli_command: the command to be run, if different from the command name
277280 :param default_flags: default flags to be used with the command
278281 :param parse: function to parse the output of the command
279282 :return:
@@ -303,7 +306,7 @@ def _run(self, command: str, *args, **kwargs):
303306 env = os .environ .copy ().update (self .env if self .env is not None else {})
304307 logger .debug (f"Running command: { ' ' .join (command_args )} " )
305308 # run the command
306- result = subprocess .run (command_args , capture_output = True , text = True , env = env )
309+ result = subprocess .run (command_args , capture_output = True , text = True , env = env , check = self . raise_exc )
307310 if result .returncode != 0 :
308311 raise RuntimeError (f"Command { command } failed with error: { result .stderr } " )
309312 return command_obj .parse (result .stdout )
@@ -314,7 +317,7 @@ async def _run_async(self, command: str, *args, **kwargs):
314317 command_args = [self .path ] + list (command_obj .build_args (* args , ** kwargs ))
315318 env = os .environ .copy ().update (self .env if self .env is not None else {})
316319 logger .error (f"Running command: { ', ' .join (command_args )} " )
317- proc = await asyncio .subprocess .create_subprocess_exec (
320+ proc = await asyncio .subprocess .create_subprocess_exec ( # pylint: disable=no-member
318321 * command_args ,
319322 stdout = asyncio .subprocess .PIPE ,
320323 stderr = asyncio .subprocess .PIPE ,
@@ -351,22 +354,22 @@ def from_dict(cls, cliwrapper_dict):
351354 else :
352355 if "cli_command" not in config :
353356 config ["cli_command" ] = command
354- commands [command ] = Command ._from_dict (config )
357+ commands [command ] = Command .from_dict (config )
355358
356359 return CLIWrapper (
357360 commands = commands ,
358361 ** cliwrapper_dict ,
359362 )
360363
361- def _to_dict (self ):
364+ def to_dict (self ):
362365 """
363366 Convert the CLIWrapper to a dictionary
364367 :return:
365368 """
366369 return {
367370 "path" : self .path ,
368371 "env" : self .env ,
369- "commands" : {k : v ._to_dict () for k , v in self .commands .items ()},
372+ "commands" : {k : v .to_dict () for k , v in self .commands .items ()},
370373 "trusting" : self .trusting ,
371374 "async_" : self .async_ ,
372375 }
0 commit comments