Skip to main content

lux_cli/
sync.rs

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