Compare commits
2 Commits
f12d6d5938
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
d04156e43a
|
|||
|
87f79ef1b9
|
@@ -1 +1,2 @@
|
|||||||
/target
|
/target
|
||||||
|
/aur
|
||||||
|
|||||||
@@ -8,10 +8,6 @@ repository = "https://git.polydevs.dev/theMZet/topaz"
|
|||||||
license="GPL-3.0-or-later"
|
license="GPL-3.0-or-later"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[features]
|
|
||||||
yay = []
|
|
||||||
paru = []
|
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
strip = true
|
strip = true
|
||||||
|
|
||||||
|
|||||||
+14
-9
@@ -31,12 +31,9 @@ use error::*;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
package_manager::{get_system_state, get_unneeded_packages, remove_packages, update_packages},
|
package_manager::{get_system_state, get_unneeded_packages, remove_packages, update_packages},
|
||||||
world::{Packages, World, get_world_location},
|
world::{PackageManager, Packages, World, get_world_location},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(all(feature = "yay", feature = "paru"))]
|
|
||||||
compile_error!("'yay' and 'paru' are mutually exclusive and cannot be enabled together.");
|
|
||||||
|
|
||||||
#[cfg(not(target_os = "linux"))]
|
#[cfg(not(target_os = "linux"))]
|
||||||
compile_error!("Only (Arch) linux is supported!");
|
compile_error!("Only (Arch) linux is supported!");
|
||||||
|
|
||||||
@@ -58,6 +55,9 @@ struct Args {
|
|||||||
#[arg(short, long, global = true)]
|
#[arg(short, long, global = true)]
|
||||||
quiet: bool,
|
quiet: bool,
|
||||||
|
|
||||||
|
#[arg(short, long, global = true)]
|
||||||
|
manager: Option<PackageManager>,
|
||||||
|
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
command: Commands,
|
command: Commands,
|
||||||
}
|
}
|
||||||
@@ -118,10 +118,10 @@ fn main() -> Result<()> {
|
|||||||
let mut x = world_state.exclude(&state);
|
let mut x = world_state.exclude(&state);
|
||||||
x.ignore = world_state.ignore.clone();
|
x.ignore = world_state.ignore.clone();
|
||||||
x.exclude_ignored();
|
x.exclude_ignored();
|
||||||
x.get_package_list()
|
x
|
||||||
};
|
};
|
||||||
|
|
||||||
update_packages(¬_installed, args.quiet)?;
|
update_packages(args.manager.unwrap_or(world.get_manager()), not_installed, args.quiet)?;
|
||||||
|
|
||||||
if !args.quiet {
|
if !args.quiet {
|
||||||
println!("Succesfully synchronized state with the world file!");
|
println!("Succesfully synchronized state with the world file!");
|
||||||
@@ -133,8 +133,13 @@ fn main() -> Result<()> {
|
|||||||
persist_ignore,
|
persist_ignore,
|
||||||
} => {
|
} => {
|
||||||
let mut world = match World::load_from(world_path.clone()) {
|
let mut world = match World::load_from(world_path.clone()) {
|
||||||
Ok(x) => x,
|
Ok(mut x) => {
|
||||||
Err(_) => World::new_empty(),
|
x.set_manager(args.manager);
|
||||||
|
x
|
||||||
|
},
|
||||||
|
Err(_) => {
|
||||||
|
World::new_empty(args.manager.unwrap_or(PackageManager::Pacman))
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut state = get_system_state()?;
|
let mut state = get_system_state()?;
|
||||||
@@ -199,7 +204,7 @@ fn main() -> Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Commands::Diff => {
|
Commands::Diff => {
|
||||||
let world = World::load_from(world_path).unwrap_or(World::new_empty());
|
let world = World::load_from(world_path).unwrap_or(World::new_empty(PackageManager::Pacman));
|
||||||
let world_state = world.get_packages();
|
let world_state = world.get_packages();
|
||||||
let state = get_system_state()?;
|
let state = get_system_state()?;
|
||||||
|
|
||||||
|
|||||||
+16
-14
@@ -1,4 +1,4 @@
|
|||||||
use crate::{PRIVLAGE_ESCELATE_COMMAND, error::Result, world::Packages};
|
use crate::{PRIVLAGE_ESCELATE_COMMAND, error::Result, world::{PackageManager, Packages}};
|
||||||
use std::process::{Command, Stdio};
|
use std::process::{Command, Stdio};
|
||||||
|
|
||||||
pub fn get_system_state() -> Result<Packages> {
|
pub fn get_system_state() -> Result<Packages> {
|
||||||
@@ -78,19 +78,21 @@ fn _update_packages(command: Command, packages: &[String], quiet: bool) -> Resul
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(feature = "yay", feature = "paru")))]
|
pub fn update_packages(manager: PackageManager, packages: Packages, quiet: bool) -> Result<()> {
|
||||||
pub fn update_packages(packages: &[String], quiet: bool) -> Result<()> {
|
let (command, packages) = match manager {
|
||||||
|
PackageManager::Pacman => {
|
||||||
let mut command = Command::new(PRIVLAGE_ESCELATE_COMMAND);
|
let mut command = Command::new(PRIVLAGE_ESCELATE_COMMAND);
|
||||||
command.arg("pacman");
|
command.arg("pacman");
|
||||||
_update_packages(command, packages, quiet)
|
(command, packages.official.clone())
|
||||||
}
|
},
|
||||||
|
PackageManager::Yay => {
|
||||||
#[cfg(feature = "yay")]
|
let command = Command::new("yay");
|
||||||
pub fn update_packages(packages: &[String], quiet: bool) -> Result<()> {
|
(command, packages.get_package_list())
|
||||||
_update_packages(Command::new("yay"), packages, quiet)
|
},
|
||||||
}
|
PackageManager::Paru => {
|
||||||
|
let command = Command::new("paru");
|
||||||
#[cfg(feature = "paru")]
|
(command, packages.get_package_list())
|
||||||
pub fn update_packages(packages: &[String], quiet: bool) -> Result<()> {
|
}
|
||||||
_update_packages(Command::new("paru"), packages, quiet)
|
};
|
||||||
|
_update_packages(command, &packages, quiet)
|
||||||
}
|
}
|
||||||
|
|||||||
+36
-1
@@ -2,6 +2,8 @@ use std::env;
|
|||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::{fs::File, path::PathBuf};
|
use std::{fs::File, path::PathBuf};
|
||||||
|
|
||||||
|
use clap::ValueEnum;
|
||||||
|
use clap::builder::PossibleValue;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::Result;
|
use crate::Result;
|
||||||
@@ -24,6 +26,28 @@ pub struct Packages {
|
|||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct World {
|
pub struct World {
|
||||||
packages: Packages,
|
packages: Packages,
|
||||||
|
manager: PackageManager,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
|
||||||
|
pub enum PackageManager {
|
||||||
|
Pacman,
|
||||||
|
Yay,
|
||||||
|
Paru,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ValueEnum for PackageManager {
|
||||||
|
fn value_variants<'a>() -> &'a [Self] {
|
||||||
|
&[Self::Pacman, Self::Yay, Self::Paru]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_possible_value(&self) -> Option<clap::builder::PossibleValue> {
|
||||||
|
match self {
|
||||||
|
PackageManager::Pacman => Some(PossibleValue::new("pacman").alias("pm").help("Pacman package manager")),
|
||||||
|
PackageManager::Yay => Some(PossibleValue::new("yay").alias("yy").help("Yay package manager")),
|
||||||
|
PackageManager::Paru => Some(PossibleValue::new("paru").alias("pr").help("Paru package manager")),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Packages {
|
impl Packages {
|
||||||
@@ -70,9 +94,10 @@ impl Packages {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl World {
|
impl World {
|
||||||
pub fn new_empty() -> World {
|
pub fn new_empty(manager: PackageManager) -> World {
|
||||||
World {
|
World {
|
||||||
packages: Packages::new(),
|
packages: Packages::new(),
|
||||||
|
manager,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,6 +109,16 @@ impl World {
|
|||||||
&mut self.packages
|
&mut self.packages
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_manager(&self) -> PackageManager {
|
||||||
|
self.manager
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_manager(&mut self, manager: Option<PackageManager>) {
|
||||||
|
if let Some(manager) = manager {
|
||||||
|
self.manager = manager;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn load_from(world_path: PathBuf) -> Result<World> {
|
pub fn load_from(world_path: PathBuf) -> Result<World> {
|
||||||
let mut file = File::open(world_path)?;
|
let mut file = File::open(world_path)?;
|
||||||
let mut text = String::new();
|
let mut text = String::new();
|
||||||
|
|||||||
Reference in New Issue
Block a user