@@ -607,6 +607,7 @@ class must be instantiated with a command argument
607607 _cmd = None
608608 _version = None
609609 _terminal_output = "stream"
610+ _write_cmdline = False
610611
611612 @classmethod
612613 def set_default_terminal_output (cls , output_type ):
@@ -623,7 +624,9 @@ def set_default_terminal_output(cls, output_type):
623624 else :
624625 raise AttributeError ("Invalid terminal output_type: %s" % output_type )
625626
626- def __init__ (self , command = None , terminal_output = None , ** inputs ):
627+ def __init__ (
628+ self , command = None , terminal_output = None , write_cmdline = False , ** inputs
629+ ):
627630 super (CommandLine , self ).__init__ (** inputs )
628631 self ._environ = None
629632 # Set command. Input argument takes precedence
@@ -638,6 +641,8 @@ def __init__(self, command=None, terminal_output=None, **inputs):
638641 if terminal_output is not None :
639642 self .terminal_output = terminal_output
640643
644+ self ._write_cmdline = write_cmdline
645+
641646 @property
642647 def cmd (self ):
643648 """sets base command, immutable"""
@@ -669,6 +674,14 @@ def terminal_output(self, value):
669674 )
670675 self ._terminal_output = value
671676
677+ @property
678+ def write_cmdline (self ):
679+ return self ._write_cmdline
680+
681+ @write_cmdline .setter
682+ def write_cmdline (self , value ):
683+ self ._write_cmdline = value is True
684+
672685 def raise_exception (self , runtime ):
673686 raise RuntimeError (
674687 (
@@ -716,9 +729,16 @@ def _run_interface(self, runtime, correct_return_codes=(0,)):
716729 adds stdout, stderr, merged, cmdline, dependencies, command_path
717730
718731 """
719-
720732 out_environ = self ._get_environ ()
721733 # Initialize runtime Bunch
734+
735+ try :
736+ runtime .cmdline = self .cmdline
737+ except Exception as exc :
738+ raise RuntimeError (
739+ "Error raised when interpolating the command line"
740+ ) from exc
741+
722742 runtime .stdout = None
723743 runtime .stderr = None
724744 runtime .cmdline = self .cmdline
@@ -742,7 +762,11 @@ def _run_interface(self, runtime, correct_return_codes=(0,)):
742762 if self ._ldd
743763 else "<skipped>"
744764 )
745- runtime = run_command (runtime , output = self .terminal_output )
765+ runtime = run_command (
766+ runtime ,
767+ output = self .terminal_output ,
768+ write_cmdline = self .write_cmdline ,
769+ )
746770 return runtime
747771
748772 def _format_arg (self , name , trait_spec , value ):
@@ -907,7 +931,14 @@ def _parse_inputs(self, skip=None):
907931
908932 if not isdefined (value ):
909933 continue
910- arg = self ._format_arg (name , spec , value )
934+
935+ try :
936+ arg = self ._format_arg (name , spec , value )
937+ except Exception as exc :
938+ raise ValueError (
939+ f"Error formatting command line argument '{ name } ' with value '{ value } '"
940+ ) from exc
941+
911942 if arg is None :
912943 continue
913944 pos = spec .position
0 commit comments