@@ -607,6 +607,7 @@ class must be instantiated with a command argument
607
607
_cmd = None
608
608
_version = None
609
609
_terminal_output = "stream"
610
+ _write_cmdline = False
610
611
611
612
@classmethod
612
613
def set_default_terminal_output (cls , output_type ):
@@ -623,7 +624,9 @@ def set_default_terminal_output(cls, output_type):
623
624
else :
624
625
raise AttributeError ("Invalid terminal output_type: %s" % output_type )
625
626
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
+ ):
627
630
super (CommandLine , self ).__init__ (** inputs )
628
631
self ._environ = None
629
632
# Set command. Input argument takes precedence
@@ -638,6 +641,8 @@ def __init__(self, command=None, terminal_output=None, **inputs):
638
641
if terminal_output is not None :
639
642
self .terminal_output = terminal_output
640
643
644
+ self ._write_cmdline = write_cmdline
645
+
641
646
@property
642
647
def cmd (self ):
643
648
"""sets base command, immutable"""
@@ -669,6 +674,14 @@ def terminal_output(self, value):
669
674
)
670
675
self ._terminal_output = value
671
676
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
+
672
685
def raise_exception (self , runtime ):
673
686
raise RuntimeError (
674
687
(
@@ -716,9 +729,16 @@ def _run_interface(self, runtime, correct_return_codes=(0,)):
716
729
adds stdout, stderr, merged, cmdline, dependencies, command_path
717
730
718
731
"""
719
-
720
732
out_environ = self ._get_environ ()
721
733
# 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
+
722
742
runtime .stdout = None
723
743
runtime .stderr = None
724
744
runtime .cmdline = self .cmdline
@@ -742,7 +762,11 @@ def _run_interface(self, runtime, correct_return_codes=(0,)):
742
762
if self ._ldd
743
763
else "<skipped>"
744
764
)
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
+ )
746
770
return runtime
747
771
748
772
def _format_arg (self , name , trait_spec , value ):
@@ -907,7 +931,14 @@ def _parse_inputs(self, skip=None):
907
931
908
932
if not isdefined (value ):
909
933
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
+
911
942
if arg is None :
912
943
continue
913
944
pos = spec .position
0 commit comments