diff --git a/src/session.rs b/src/session.rs index 8c175a2a..273cbb8c 100644 --- a/src/session.rs +++ b/src/session.rs @@ -184,27 +184,27 @@ impl DerefMut for PtySession { } } -/// Start a process in a tty session, write and read from it -/// -/// # Example -/// -/// ``` -/// -/// use rexpect::spawn; -/// # use rexpect::error::Error; -/// -/// # fn main() { -/// # || -> Result<(), Error> { -/// let mut s = spawn("cat", Some(1000))?; -/// s.send_line("hello, polly!")?; -/// let line = s.read_line()?; -/// assert_eq!("hello, polly!", line); -/// # Ok(()) -/// # }().expect("test failed"); -/// # } -/// ``` impl PtySession { - fn new(process: PtyProcess, options: Options) -> Result { + /// Start a process in a tty session, write and read from it + /// + /// # Example + /// + /// ``` + /// + /// use rexpect::spawn; + /// # use rexpect::error::Error; + /// + /// # fn main() { + /// # || -> Result<(), Error> { + /// let mut s = spawn("cat", Some(1000))?; + /// s.send_line("hello, polly!")?; + /// let line = s.read_line()?; + /// assert_eq!("hello, polly!", line); + /// # Ok(()) + /// # }().expect("test failed"); + /// # } + /// ``` + pub fn new(process: PtyProcess, options: Options) -> Result { let f = process.get_file_handle()?; let reader = f.try_clone()?; let stream = StreamSession::new(reader, f, options); @@ -212,12 +212,6 @@ impl PtySession { } } -/// Turn e.g. "prog arg1 arg2" into ["prog", "arg1", "arg2"] -/// Also takes care of single and double quotes -fn tokenize_command(program: &str) -> Result, Error> { - comma::parse_command(program).ok_or(Error::BadProgramArguments) -} - /// Start command in background in a pty session (pty fork) and return a struct /// with writer and buffered reader (for unblocking reads). /// @@ -243,6 +237,12 @@ pub fn spawn(program: &str, timeout_ms: Option) -> Result Result, Error> { + comma::parse_command(program).ok_or(Error::BadProgramArguments) +} + /// See [`spawn`] pub fn spawn_command(command: Command, timeout_ms: Option) -> Result { spawn_with_options(