feat: sync subcommand
This commit is contained in:
+19
-2
@@ -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(¬_installed)?;
|
||||||
|
|
||||||
|
if !args.quiet {
|
||||||
|
println!("Succesfully synchronized state with the world file!");
|
||||||
|
}
|
||||||
|
}
|
||||||
Commands::Export {
|
Commands::Export {
|
||||||
overwrite,
|
overwrite,
|
||||||
stdout,
|
stdout,
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user