feat: sync subcommand

This commit is contained in:
2026-05-30 00:41:44 +02:00
parent 5a614e366e
commit 027efa3f83
2 changed files with 48 additions and 2 deletions
+19 -2
View File
@@ -30,7 +30,7 @@ mod world;
use error::*; use error::*;
use crate::{ use crate::{
package_manager::{get_system_state, get_unneeded_packages, remove_packages}, package_manager::{get_system_state, get_unneeded_packages, remove_packages, update_packages},
world::{World, get_world_location}, world::{World, get_world_location},
}; };
@@ -99,7 +99,24 @@ fn main() -> Result<()> {
}; };
match args.command { match args.command {
Commands::Sync => todo!(), Commands::Sync => {
let world = World::load_from(world_path)?;
let world_state = world.get_packages();
let state = get_system_state()?;
let not_installed = {
let mut x = world_state.exclude(&state);
x.ignore = world_state.ignore.clone();
x.exclude_ignored();
x.get_package_list()
};
update_packages(&not_installed)?;
if !args.quiet {
println!("Succesfully synchronized state with the world file!");
}
}
Commands::Export { Commands::Export {
overwrite, overwrite,
stdout, stdout,
+29
View File
@@ -62,3 +62,32 @@ pub fn remove_packages(packages: &[String], all: bool) -> Result<()> {
Ok(()) Ok(())
} }
fn _update_packages(command: Command, packages: &[String]) -> Result<()> {
let mut command = command;
command
.arg("-Syu")
.args(packages)
.stderr(Stdio::inherit())
.stdout(Stdio::inherit())
.stdin(Stdio::inherit())
.status()?;
Ok(())
}
#[cfg(not(any(feature = "yay", feature = "paru")))]
pub fn update_packages(packages: &[String]) -> Result<()> {
let mut command = Command::new(PRIVLAGE_ESCELATE_COMMAND);
command.arg("pacman");
_update_packages(command, packages)
}
#[cfg(feature = "yay")]
pub fn update_packages(packages: &[String]) -> Result<()> {
_update_packages(Command::new("yay"), packages)
}
#[cfg(feature = "paru")]
pub fn update_packages(packages: &[String]) -> Result<()> {
_update_packages(Command::new("paru"), packages)
}