rrun_ssh/
program_args.rs

1use std::ffi::OsString;
2use std::process::Command;
3
4
5/// Builder for the command-line arguments for a program.
6#[derive(Clone, Debug, Eq, PartialEq)]
7pub struct ProgramArgs {
8    program: OsString,
9    args: Vec<OsString>,
10}
11impl ProgramArgs {
12    /// Creates a builder for `ProgramArgs` from a program name.
13    #[inline]
14    pub fn new<S: Into<OsString>>(program: S) -> ProgramArgs {
15        ProgramArgs {
16            program: program.into(),
17            args: Vec::new(),
18        }
19    }
20
21    /// Appends a single argument.
22    #[inline]
23    pub fn push<S: Into<OsString>>(&mut self, arg: S) {
24        self.args.push(arg.into());
25    }
26
27    /// Converts these arguments into a command to run.
28    pub fn into_command(self) -> Command {
29        let mut cmd = Command::new(&self.program);
30        cmd.args(&self.args);
31        cmd
32    }
33}
34impl<S: Into<OsString>> Extend<S> for ProgramArgs {
35    fn extend<T: IntoIterator<Item = S>>(&mut self, iterable: T) {
36        self.args.extend(iterable.into_iter().map(Into::into));
37    }
38}