std::process::Command has no way to mutate the supplied arguments when one wants to execute a process again. Sometimes (esp in testsuites) this is required.
The other attributes (environment variables, current_dir) have API's for mutating them.
Therefore I'd like to propose/discuss what could be done for the commands args.
Traditionally program arguments are an array of strings where argv[0]
is slightly special as
it (usually) contains the program name, it can still be changed but is not part of the
arguments handled by the argument parser. std::process::Command will already initialize that
for you.
For mutating the argv as bare minimum I'd propose:
pub fn args_reset()
Shall reset the argument vector to the state it was when
Commmand::new()
created it. That is: setting its length to 1 keeping argv[0]
intact.
Furher (to be discussed) API's may be:
pub fn arg_set(index: usize, value: &str) -> Result<(), Error>
replacing the argument at the given index, results in an error when the index was out of
range. This can be used to change argv[0]
pub fn arg_pop() -> Result<(), Error>
// and/or
pub fn args_pop(n: usize) -> Result<(), Error>
drops the last element / n last elements
returns an Error when there are less elements available. (discussion: shall argv[0]
be preserved?)
pub fn args_new<I, S>(&mut self, args: I) -> &mut Command where
I: IntoIterator<Item = S>,
S: AsRef<OsStr>,
sets a new list of arguments, like args_reset()
followed by args()
. leaves argv[0] untouched