<commit_before>//! The `conductor up` command.

use command_runner::{Command, CommandRunner};
#[cfg(test)]
use command_runner::TestCommandRunner;
use ovr::Override;
use project::Project;
use util::Error;

/// We implement `conductor up` with a trait so we put it in its own module.
pub trait CommandUp {
    /// Up all the images associated with a project.
    fn up<CR>(&self, runner: &CR, ovr: &Override) -> Result<(), Error>
        where CR: CommandRunner;
}

impl CommandUp for Project {
    fn up<CR>(&self, runner: &CR, ovr: &Override) -> Result<(), Error>
        where CR: CommandRunner
    {
        for pod in self.pods() {
            // We pass `-d` because we need to detach from each pod to
            // launch the next.  To avoid this, we'd need to use multiple
            // parallel threads and maybe some intelligent output
            // buffering.
            let status = try!(runner.build("docker-compose")
                .args(&try!(pod.compose_args(self, ovr)))
                .arg("up").arg("-d")
                .status());
            if !status.success() {
                return Err(err!("Error running docker-compose"));
            }
        }
        Ok(())
    }
}

#[test]
fn runs_docker_compose_up_on_all_pods() {
    use env_logger;
    let _ = env_logger::init();
    let proj = Project::from_example("hello").unwrap();
    let ovr = proj.ovr("development").unwrap();
    let runner = TestCommandRunner::new();
    proj.output().unwrap();
    proj.up(&runner, &ovr).unwrap();<commit_msg>Don't start one-shot tasks on `up`<commit_after>//! The `conductor up` command.

use command_runner::{Command, CommandRunner};
#[cfg(test)]
use command_runner::TestCommandRunner;
use ovr::Override;
use pod::PodType;
use project::Project;
use util::Error;

/// We implement `conductor up` with a trait so we put it in its own module.
pub trait CommandUp {
    /// Up all the images associated with a project.
    fn up<CR>(&self, runner: &CR, ovr: &Override) -> Result<(), Error>
        where CR: CommandRunner;
}

impl CommandUp for Project {
    fn up<CR>(&self, runner: &CR, ovr: &Override) -> Result<(), Error>
        where CR: CommandRunner
    {
        for pod in self.pods() {
            if try!(pod.pod_type(ovr)) == PodType::Service {
                // We pass `-d` because we need to detach from each pod to
                // launch the next.  To avoid this, we'd need to use
                // multiple parallel threads and maybe some intelligent
                // output buffering.
                let status = try!(runner.build("docker-compose")
                    .args(&try!(pod.compose_args(self, ovr)))
                    .arg("up").arg("-d")
                    .status());
                if !status.success() {
                    return Err(err!("Error running docker-compose"));
                }
            }
        }
        Ok(())
    }
}

#[test]
fn runs_docker_compose_up_on_all_pods() {
    use env_logger;
    let _ = env_logger::init();
    let proj = Project::from_example("hello").unwrap();
    let ovr = proj.ovr("development").unwrap();
    let runner = TestCommandRunner::new();
    proj.output().unwrap();
    proj.up(&runner, &ovr).unwrap();
{'fraction_non_alphanumeric': 0.14201367308887508, 'fraction_numerical': 0.0, 'mean_word_length': 2.3117283950617282, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3251686', 'n_tokens_mistral': 971, 'n_tokens_neox': 946, 'n_words': 283}