File tree 1 file changed +42
-0
lines changed
1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -714,6 +714,48 @@ impl Command {
714
714
self
715
715
}
716
716
717
+ /// Reset the argument list to new content
718
+ ///
719
+ /// Allows to maintain the argument list in a Vec or anything else that can provide
720
+ /// a suitable iterator.
721
+ ///
722
+ /// # Examples
723
+ ///
724
+ /// Basic usage:
725
+ ///
726
+ /// ```no_run
727
+ /// #![feature(mutate_command_args)]
728
+ /// use std::process::Command;
729
+ ///
730
+ /// // Prepare a command
731
+ /// let mut command = Command::new("ls");
732
+ /// let mut my_args = Vec::from(["-l", "foo"]);
733
+ ///
734
+ /// command
735
+ /// .args_new(&my_args)
736
+ /// .spawn()
737
+ /// .unwrap();
738
+ ///
739
+ /// // Mutate my_args
740
+ /// my_args.insert(1, "-a");
741
+ /// my_args.pop();
742
+ /// my_args.push("bar");
743
+ ///
744
+ /// // Run command again with the mutated arguments
745
+ /// command
746
+ /// .args_new(&my_args)
747
+ /// .spawn()
748
+ /// .unwrap();
749
+ /// ```
750
+ #[ unstable( feature = "mutate_command_args" , issue = "87379" ) ]
751
+ pub fn args_new < I , S > ( & mut self , args : I ) -> & mut Command
752
+ where
753
+ I : IntoIterator < Item = S > ,
754
+ S : AsRef < OsStr > ,
755
+ {
756
+ self . args_clear ( ) . args ( args)
757
+ }
758
+
717
759
/// Inserts or updates an environment variable mapping.
718
760
///
719
761
/// Note that environment variable names are case-insensitive (but case-preserving) on Windows,
You can’t perform that action at this time.
0 commit comments