Skip to main content

lux_cli/
sync.rs

1use clap::Args;
2use lux_lib::{
3    config::Config,
4    drivers::sync::{Sync, SyncMode, TargetSet},
5    workspace::Workspace,
6};
7
8use miette::Result;
9
10#[derive(Args)]
11pub struct SyncProject {
12    /// Skip the integrity checks for installed rocks when syncing the project lockfile.
13    #[arg(long)]
14    no_integrity_check: bool,
15}
16
17/// Sync the current project's installed packages with its lux.toml.
18pub async fn sync(args: SyncProject, config: Config) -> Result<()> {
19    let workspace = Workspace::current_or_err()?;
20
21    let report = Sync::new(&workspace, &config)
22        .mode(SyncMode::Frozen)
23        .targets(TargetSet::all(&workspace, true))
24        .validate_integrity(!args.no_integrity_check)
25        .sync()
26        .await?;
27
28    if report.added().is_empty() && report.removed().is_empty() {
29        println!("Already in sync.");
30        return Ok(());
31    }
32
33    for pkg in report.added() {
34        println!("+ {} {}", pkg.name(), pkg.version());
35    }
36    for pkg in report.removed() {
37        println!("- {} {}", pkg.name(), pkg.version());
38    }
39
40    Ok(())
41}