But what if you wanted to use the same program (and probably current directory) for several steps? You have to create new commands for every step like this:
In this case it would be nice if Command allowed us to change its arguments but keep the program like this:
let mut git = Command::new("git");
git.current_dir("/home/zooce/project");
// just using `set_args` to differentiate from `args`
git.set_args(["fetch", "-a"]).output()?;
git.set_args(["pull"]).output()?;
git.set_args(["submodule", "udpate", "--init", "--recursive"]).output()?;
This might be kind of a dumb example, but I think it gets the point across.
I also want to note that std::process::Command already has a way to achieve this for environment variables with clear_env() so you can have a new set of environment variables but use the same instance of Command. So another possibility is to add a clear_args() function: