1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//! Comamnd Upgrade

use crate::{
    registry::{redep, Registry},
    result::{Error, Result},
};
use std::path::PathBuf;

/// Exec command `upgrade`
pub fn exec(path: PathBuf, mut tag: String, update: bool) -> Result<()> {
    let registry = Registry::new()?;
    if update {
        println!("Fetching registry...");
        registry.update()?;
    }

    // tags
    let tags = registry.tag()?;
    if tag.is_empty() && tags.len() > 0 {
        tag = tags[tags.len() - 1].clone();
    } else if !tags.contains(&tag) {
        return Err(Error::Sup(format!(
            "The registry at {} doesn't have tag {}",
            registry.0, tag,
        )));
    }

    // Checkout to the target tag
    registry.checkout(&tag)?;
    let crates = etc::find_all(path, "Cargo.toml")?;
    for ct in crates {
        redep(&ct, &registry)?;
    }

    // Checkout back to the latest commit
    registry.checkout("master")?;
    Ok(())
}