use std::error::Error; use std::fmt; use std::io; use command_runner::CommandRunner; use symbols::Symbol; pub struct GitSubmodules<'a> { target: &'a str, command_runner: &'a CommandRunner } impl<'a> GitSubmodules<'a> { pub fn new(target: &'a str, command_runner: &'a CommandRunner) -> GitSubmodules<'a> { GitSubmodules { target: target, command_runner: command_runner } } } impl<'a> fmt::Display for GitSubmodules<'a> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Submodules for {}", self.target) } } impl<'a> GitSubmodules<'a> { fn _run_in_target_repo(&self, args: &[&str]) -> Result, io::Error> { let mut new_args = vec!["-C", self.target]; new_args.extend_from_slice(args); self.command_runner.run_with_args("git", &new_args).map(|res| res.stdout) } } impl<'a> Symbol for GitSubmodules<'a> { fn target_reached(&self) -> Result> { let output = try!(self._run_in_target_repo(&["submodule", "status"])); Ok(String::from_utf8(output).unwrap().lines().all(|line| line.len() == 0 || line.starts_with(' '))) } fn execute(&self) -> Result<(), Box> { try!(self._run_in_target_repo(&["submodule", "update", "--init"])); Ok(()) } } #[cfg(test)] mod test { }