mirror of
https://github.com/eRgo35/ah.git
synced 2026-02-04 05:16:09 +01:00
initial prototype complete
This commit is contained in:
25
src/cli.rs
25
src/cli.rs
@@ -5,8 +5,9 @@ use clap::{Args, Parser, Subcommand};
|
|||||||
name = "ah",
|
name = "ah",
|
||||||
author = "Michał Czyż",
|
author = "Michał Czyż",
|
||||||
version = "0.1.0",
|
version = "0.1.0",
|
||||||
about = "A declarative package manager for Arch Linux",
|
about = "A declarative package manager for Arch Linux",
|
||||||
long_about = "Arch Helper is a declarative package management tool for Arch Linux. It leverages paru or other package managers for seamless integration.")]
|
long_about = "Arch Helper is a declarative package management tool for Arch Linux. It leverages paru or other package managers for seamless integration."
|
||||||
|
)]
|
||||||
pub struct Cli {
|
pub struct Cli {
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
pub command: Option<Commands>,
|
pub command: Option<Commands>,
|
||||||
@@ -14,25 +15,25 @@ pub struct Cli {
|
|||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
pub enum Commands {
|
pub enum Commands {
|
||||||
#[command(about = "Install packages")]
|
#[command(alias = "i", about = "Install packages")]
|
||||||
Install(PackageList),
|
Install(PackageList),
|
||||||
|
|
||||||
#[command(about = "Upgrade packages")]
|
#[command(alias = "u", about = "Upgrade packages")]
|
||||||
Upgrade {
|
Upgrade {
|
||||||
#[arg(help = "Don't prompt for confirmation", default_value_t = false)]
|
#[arg(help = "Don't prompt for confirmation", default_value_t = false)]
|
||||||
noconfirm: bool
|
noconfirm: bool,
|
||||||
},
|
},
|
||||||
|
|
||||||
#[command(about = "Synchronize packages")]
|
#[command(alias = "s", about = "Synchronize packages")]
|
||||||
Sync {
|
Sync {
|
||||||
#[arg(help = "Don't prompt for confirmation", default_value_t = false)]
|
#[arg(help = "Don't prompt for confirmation", default_value_t = false)]
|
||||||
noconfirm: bool
|
noconfirm: bool,
|
||||||
},
|
},
|
||||||
|
|
||||||
#[command(about = "Remove packages")]
|
#[command(alias = "r", about = "Remove packages")]
|
||||||
Remove(PackageList),
|
Remove(PackageList),
|
||||||
|
|
||||||
#[command(about = "Find packages")]
|
#[command(alias = "f", about = "Find packages")]
|
||||||
Find(Query),
|
Find(Query),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,4 +47,4 @@ pub struct PackageList {
|
|||||||
pub struct Query {
|
pub struct Query {
|
||||||
#[arg(help = "Search term for finding packages")]
|
#[arg(help = "Search term for finding packages")]
|
||||||
pub query: Vec<String>,
|
pub query: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|||||||
39
src/file.rs
39
src/file.rs
@@ -1,6 +1,7 @@
|
|||||||
use std::{
|
use std::{
|
||||||
fs::File,
|
fs::{File, OpenOptions},
|
||||||
io::{prelude::*, BufReader}, path::PathBuf,
|
io::{prelude::*, BufReader},
|
||||||
|
path::PathBuf,
|
||||||
};
|
};
|
||||||
|
|
||||||
// pub fn read_config(path: &str) -> Vec<String> {
|
// pub fn read_config(path: &str) -> Vec<String> {
|
||||||
@@ -12,12 +13,34 @@ use std::{
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
pub fn read_packages(path: PathBuf) -> Vec<String> {
|
pub fn read_packages(path: PathBuf) -> Vec<String> {
|
||||||
let file = File::open(path).expect("Failed to open file");
|
let file = File::open(path).expect("Failed to open file");
|
||||||
let buf = BufReader::new(file);
|
let buf = BufReader::new(file);
|
||||||
|
|
||||||
buf.lines().map(|l| l.expect("Failed to read line")).collect()
|
buf.lines()
|
||||||
|
.map(|l| l.expect("Failed to read line"))
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub fn write_packages(path: &str, content: &str) {
|
pub fn append_package(path: PathBuf, package: &str) {
|
||||||
// todo!();
|
let mut file = OpenOptions::new()
|
||||||
// }
|
.write(true)
|
||||||
|
.append(true)
|
||||||
|
.open(path)
|
||||||
|
.expect("Failed to open file");
|
||||||
|
|
||||||
|
if let Err(err) = writeln!(file, "{}", package) {
|
||||||
|
eprintln!("Couldn't write to file: {}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn write_packages(path: PathBuf, content: &str) {
|
||||||
|
let mut file = OpenOptions::new()
|
||||||
|
.write(true)
|
||||||
|
.truncate(true)
|
||||||
|
.open(path)
|
||||||
|
.expect("Failed to open file");
|
||||||
|
|
||||||
|
if let Err(err) = writeln!(file, "{}", content) {
|
||||||
|
eprintln!("Couldn't write to file: {}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ use cli::{PackageList, Query};
|
|||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
|
|
||||||
mod cli;
|
mod cli;
|
||||||
mod packages;
|
|
||||||
mod file;
|
mod file;
|
||||||
|
mod packages;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let cli = cli::Cli::parse();
|
let cli = cli::Cli::parse();
|
||||||
|
|||||||
@@ -4,21 +4,25 @@ use std::process::Command;
|
|||||||
const PACKAGE_MANAGER: &str = "paru";
|
const PACKAGE_MANAGER: &str = "paru";
|
||||||
|
|
||||||
pub fn find(query: Vec<String>) -> Result<(), Box<dyn std::error::Error>> {
|
pub fn find(query: Vec<String>) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
println!("{} {}", "::".bold().green(), "Looking for package...".bold());
|
println!(
|
||||||
|
"{} {}",
|
||||||
|
"::".bold().green(),
|
||||||
|
"Looking for package...".bold()
|
||||||
|
);
|
||||||
|
|
||||||
if query.is_empty() {
|
if query.is_empty() {
|
||||||
return Err("No query provided".into());
|
return Err("No query provided".into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let output = Command::new(PACKAGE_MANAGER)
|
let output = Command::new(PACKAGE_MANAGER)
|
||||||
.arg("--color")
|
.arg("--color")
|
||||||
.arg("always")
|
.arg("always")
|
||||||
.arg("-Ss")
|
.arg("-Ss")
|
||||||
.args(query)
|
.args(query)
|
||||||
.output()
|
.output()
|
||||||
.expect("Failed to execute command");
|
.expect("Failed to execute command");
|
||||||
|
|
||||||
print!("{}", String::from_utf8_lossy(&output.stdout));
|
print!("{}", String::from_utf8_lossy(&output.stdout));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,62 @@
|
|||||||
|
use crate::{file, packages::get_package_path};
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
|
use std::io::Write;
|
||||||
|
use std::process::{Command, Stdio};
|
||||||
|
|
||||||
pub fn install(_package: Vec<String>) -> Result<(), Box<dyn std::error::Error>> {
|
const PACKAGE_MANAGER: &str = "paru";
|
||||||
println!("{} {}", "::".bold().green(), "Installing packages...".bold());
|
|
||||||
todo!();
|
pub fn install(new_packages: Vec<String>) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
}
|
println!(
|
||||||
|
"{} {}",
|
||||||
|
"::".bold().green(),
|
||||||
|
"Installing packages...".bold()
|
||||||
|
);
|
||||||
|
|
||||||
|
let packages = file::read_packages(get_package_path());
|
||||||
|
|
||||||
|
let packages = packages
|
||||||
|
.into_iter()
|
||||||
|
.filter(|p| !p.contains("#") && !p.is_empty())
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
|
||||||
|
let mut child = Command::new(PACKAGE_MANAGER)
|
||||||
|
.arg("--color")
|
||||||
|
.arg("always")
|
||||||
|
.arg("-S")
|
||||||
|
.arg("--needed")
|
||||||
|
// .arg(noconfirm)
|
||||||
|
.arg("-")
|
||||||
|
.stdin(Stdio::piped())
|
||||||
|
.stdout(Stdio::inherit())
|
||||||
|
.stderr(Stdio::inherit())
|
||||||
|
.spawn()
|
||||||
|
.expect("Failed to execute command");
|
||||||
|
|
||||||
|
if let Some(mut stdin) = child.stdin.take() {
|
||||||
|
for new_package in new_packages.clone() {
|
||||||
|
writeln!(stdin, "{}", new_package).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let status = child.wait().expect("Failed to wait on child");
|
||||||
|
|
||||||
|
if !status.success() {
|
||||||
|
return Err("Failed to install packages".into());
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("{} {}", "::".bold().green(), "Packages installed".bold());
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"{} {}",
|
||||||
|
"::".bold().blue(),
|
||||||
|
"Updating package index...".bold()
|
||||||
|
);
|
||||||
|
|
||||||
|
for new_package in new_packages {
|
||||||
|
if !packages.contains(&new_package) {
|
||||||
|
file::append_package(get_package_path(), &new_package);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,34 +1,38 @@
|
|||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use std::path::PathBuf;
|
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
pub mod find;
|
||||||
|
pub mod install;
|
||||||
pub mod rebuild;
|
pub mod rebuild;
|
||||||
|
pub mod remove;
|
||||||
pub mod sync;
|
pub mod sync;
|
||||||
pub mod upgrade;
|
pub mod upgrade;
|
||||||
pub mod install;
|
|
||||||
pub mod remove;
|
|
||||||
pub mod find;
|
|
||||||
|
|
||||||
|
pub use find::find;
|
||||||
|
pub use install::install;
|
||||||
pub use rebuild::rebuild;
|
pub use rebuild::rebuild;
|
||||||
|
pub use remove::remove;
|
||||||
pub use sync::sync;
|
pub use sync::sync;
|
||||||
pub use upgrade::upgrade;
|
pub use upgrade::upgrade;
|
||||||
pub use install::install;
|
|
||||||
pub use remove::remove;
|
|
||||||
pub use find::find;
|
|
||||||
|
|
||||||
fn get_package_path() -> PathBuf {
|
fn get_package_path() -> PathBuf {
|
||||||
let home_dir = std::env::var("HOME").unwrap();
|
let home_dir = std::env::var("HOME").unwrap();
|
||||||
|
|
||||||
PathBuf::from(home_dir).join("packages")
|
PathBuf::from(home_dir).join("packages")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ask_confirmation() -> Result<bool, io::Error> {
|
fn ask_confirmation() -> Result<bool, io::Error> {
|
||||||
print!("{} {}", "::".bold().blue(), "Do you want to continue? [Y/n] ");
|
print!(
|
||||||
io::stdout().flush()?;
|
"{} {}",
|
||||||
|
"::".bold().blue(),
|
||||||
|
"Do you want to continue? [Y/n] "
|
||||||
|
);
|
||||||
|
io::stdout().flush()?;
|
||||||
|
|
||||||
let mut input = String::new();
|
let mut input = String::new();
|
||||||
io::stdin().read_line(&mut input)?;
|
io::stdin().read_line(&mut input)?;
|
||||||
|
|
||||||
let input = input.trim().to_lowercase();
|
let input = input.trim().to_lowercase();
|
||||||
Ok(input.is_empty() || input == "y")
|
Ok(input.is_empty() || input == "y")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use std::process::{Command, Stdio};
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
use std::process::{Command, Stdio};
|
||||||
|
|
||||||
use crate::file;
|
use crate::file;
|
||||||
use crate::packages::{ask_confirmation, get_package_path};
|
use crate::packages::{ask_confirmation, get_package_path};
|
||||||
@@ -8,45 +8,58 @@ use crate::packages::{ask_confirmation, get_package_path};
|
|||||||
const PACKAGE_MANAGER: &str = "paru";
|
const PACKAGE_MANAGER: &str = "paru";
|
||||||
|
|
||||||
pub fn rebuild(noconfirm: bool) -> Result<(), Box<dyn std::error::Error>> {
|
pub fn rebuild(noconfirm: bool) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
println!("{} {}", "::".bold().green(), "Upgrading & syncing packages...".bold());
|
println!(
|
||||||
|
"{} {}",
|
||||||
|
"::".bold().green(),
|
||||||
|
"Upgrading & syncing packages...".bold()
|
||||||
|
);
|
||||||
|
|
||||||
if !ask_confirmation()? {
|
if !ask_confirmation()? {
|
||||||
return Err("Operation aborted".into());
|
return Err("Operation aborted".into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let packages = file::read_packages(get_package_path());
|
let packages = file::read_packages(get_package_path());
|
||||||
|
|
||||||
let packages = packages.into_iter()
|
let packages = packages
|
||||||
.filter(|p| !p.contains("#") && !p.is_empty())
|
.into_iter()
|
||||||
.collect::<Vec<String>>();
|
.filter(|p| !p.contains("#") && !p.is_empty())
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
|
||||||
let noconfirm = if noconfirm { "--noconfirm" } else { "--confirm" };
|
let noconfirm = if noconfirm {
|
||||||
|
"--noconfirm"
|
||||||
|
} else {
|
||||||
|
"--confirm"
|
||||||
|
};
|
||||||
|
|
||||||
let mut child = Command::new(PACKAGE_MANAGER)
|
let mut child = Command::new(PACKAGE_MANAGER)
|
||||||
.arg("--color")
|
.arg("--color")
|
||||||
.arg("always")
|
.arg("always")
|
||||||
.arg("-Syu")
|
.arg("-Syu")
|
||||||
.arg("--needed")
|
.arg("--needed")
|
||||||
.arg(noconfirm)
|
.arg(noconfirm)
|
||||||
.arg("-")
|
.arg("-")
|
||||||
.stdin(Stdio::piped())
|
.stdin(Stdio::piped())
|
||||||
.stdout(Stdio::inherit())
|
.stdout(Stdio::inherit())
|
||||||
.stderr(Stdio::inherit())
|
.stderr(Stdio::inherit())
|
||||||
.spawn()
|
.spawn()
|
||||||
.expect("Failed to execute command");
|
.expect("Failed to execute command");
|
||||||
|
|
||||||
if let Some(mut stdin) = child.stdin.take() {
|
if let Some(mut stdin) = child.stdin.take() {
|
||||||
for package in packages {
|
for package in packages {
|
||||||
writeln!(stdin, "{}", package).unwrap();
|
writeln!(stdin, "{}", package).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let status = child.wait().expect("Failed to wait on child");
|
let status = child.wait().expect("Failed to wait on child");
|
||||||
|
|
||||||
if !status.success() {
|
if !status.success() {
|
||||||
return Err("Failed to upgrade & sync packages".into());
|
return Err("Failed to upgrade & sync packages".into());
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("{} {}", "::".bold().green(), "Packages upgraded & synced".bold());
|
println!(
|
||||||
Ok(())
|
"{} {}",
|
||||||
|
"::".bold().green(),
|
||||||
|
"Packages upgraded & synced".bold()
|
||||||
|
);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,58 @@
|
|||||||
|
use crate::{file, packages::get_package_path};
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
|
use std::io::Write;
|
||||||
|
use std::process::{Command, Stdio};
|
||||||
|
|
||||||
pub fn remove(_package: Vec<String>) -> Result<(), Box<dyn std::error::Error>> {
|
const PACKAGE_MANAGER: &str = "paru";
|
||||||
println!("{} {}", "::".bold().green(), "Removing packages...".bold());
|
|
||||||
todo!();
|
pub fn remove(unwanted_packages: Vec<String>) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
}
|
println!("{} {}", "::".bold().green(), "Removing packages...".bold());
|
||||||
|
|
||||||
|
let packages = file::read_packages(get_package_path());
|
||||||
|
|
||||||
|
let mut packages = packages
|
||||||
|
.into_iter()
|
||||||
|
.filter(|p| !p.contains("#") && !p.is_empty())
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
|
||||||
|
let mut child = Command::new(PACKAGE_MANAGER)
|
||||||
|
.arg("--color")
|
||||||
|
.arg("always")
|
||||||
|
.arg("-R")
|
||||||
|
// .arg("--needed")
|
||||||
|
// .arg(noconfirm)
|
||||||
|
.arg("-")
|
||||||
|
.stdin(Stdio::piped())
|
||||||
|
.stdout(Stdio::inherit())
|
||||||
|
.stderr(Stdio::inherit())
|
||||||
|
.spawn()
|
||||||
|
.expect("Failed to execute command");
|
||||||
|
|
||||||
|
if let Some(mut stdin) = child.stdin.take() {
|
||||||
|
for unwanted_package in unwanted_packages.clone() {
|
||||||
|
writeln!(stdin, "{}", unwanted_package).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let status = child.wait().expect("Failed to wait on child");
|
||||||
|
|
||||||
|
if !status.success() {
|
||||||
|
return Err("Failed to remove packages".into());
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("{} {}", "::".bold().green(), "Packages removed".bold());
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"{} {}",
|
||||||
|
"::".bold().blue(),
|
||||||
|
"Updating package index...".bold()
|
||||||
|
);
|
||||||
|
|
||||||
|
for unwanted_package in unwanted_packages {
|
||||||
|
packages.retain(|p| *p != unwanted_package);
|
||||||
|
}
|
||||||
|
|
||||||
|
file::write_packages(get_package_path(), &packages.join("\n"));
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,48 +1,57 @@
|
|||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use std::process::{Command, Stdio};
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
use std::process::{Command, Stdio};
|
||||||
|
|
||||||
use crate::file;
|
use crate::file;
|
||||||
use crate::packages::get_package_path;
|
use crate::packages::{ask_confirmation, get_package_path};
|
||||||
|
|
||||||
const PACKAGE_MANAGER: &str = "paru";
|
const PACKAGE_MANAGER: &str = "paru";
|
||||||
|
|
||||||
pub fn sync(noconfirm: bool) -> Result<(), Box<dyn std::error::Error>> {
|
pub fn sync(noconfirm: bool) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
println!("{} {}", "::".bold().green(), "Syncing packages...".bold());
|
println!("{} {}", "::".bold().green(), "Syncing packages...".bold());
|
||||||
|
|
||||||
let packages = file::read_packages(get_package_path());
|
if !ask_confirmation()? {
|
||||||
|
return Err("Operation aborted".into());
|
||||||
|
}
|
||||||
|
|
||||||
let packages = packages.into_iter()
|
let packages = file::read_packages(get_package_path());
|
||||||
.filter(|p| !p.contains("#") && !p.is_empty())
|
|
||||||
.collect::<Vec<String>>();
|
|
||||||
|
|
||||||
let noconfirm = if noconfirm { "--noconfirm" } else { "--confirm" };
|
let packages = packages
|
||||||
|
.into_iter()
|
||||||
|
.filter(|p| !p.contains("#") && !p.is_empty())
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
|
||||||
let mut child = Command::new(PACKAGE_MANAGER)
|
let noconfirm = if noconfirm {
|
||||||
.arg("--color")
|
"--noconfirm"
|
||||||
.arg("always")
|
} else {
|
||||||
.arg("-S")
|
"--confirm"
|
||||||
.arg("--needed")
|
};
|
||||||
.arg(noconfirm)
|
|
||||||
.arg("-")
|
|
||||||
.stdin(Stdio::piped())
|
|
||||||
.stdout(Stdio::inherit())
|
|
||||||
.stderr(Stdio::inherit())
|
|
||||||
.spawn()
|
|
||||||
.expect("Failed to execute command");
|
|
||||||
|
|
||||||
if let Some(mut stdin) = child.stdin.take() {
|
let mut child = Command::new(PACKAGE_MANAGER)
|
||||||
for package in packages {
|
.arg("--color")
|
||||||
writeln!(stdin, "{}", package).unwrap();
|
.arg("always")
|
||||||
}
|
.arg("-S")
|
||||||
}
|
.arg("--needed")
|
||||||
|
.arg(noconfirm)
|
||||||
|
.arg("-")
|
||||||
|
.stdin(Stdio::piped())
|
||||||
|
.stdout(Stdio::inherit())
|
||||||
|
.stderr(Stdio::inherit())
|
||||||
|
.spawn()
|
||||||
|
.expect("Failed to execute command");
|
||||||
|
|
||||||
let status = child.wait().expect("Failed to wait on child");
|
if let Some(mut stdin) = child.stdin.take() {
|
||||||
|
for package in packages {
|
||||||
|
writeln!(stdin, "{}", package).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if !status.success() {
|
let status = child.wait().expect("Failed to wait on child");
|
||||||
return Err("Failed to sync packages".into());
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("{} {}", "::".bold().green(), "Packages synced".bold());
|
if !status.success() {
|
||||||
Ok(())
|
return Err("Failed to sync packages".into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println!("{} {}", "::".bold().green(), "Packages synced".bold());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,27 +1,37 @@
|
|||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
|
use crate::packages::ask_confirmation;
|
||||||
|
|
||||||
const PACKAGE_MANAGER: &str = "paru";
|
const PACKAGE_MANAGER: &str = "paru";
|
||||||
|
|
||||||
pub fn upgrade(noconfirm: bool) -> Result<(), Box<dyn std::error::Error>> {
|
pub fn upgrade(noconfirm: bool) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
println!("{} {}", "::".bold().green(), "Upgrading packages...".bold());
|
println!("{} {}", "::".bold().green(), "Upgrading packages...".bold());
|
||||||
|
|
||||||
let noconfirm = if noconfirm { "--noconfirm" } else { "--confirm" };
|
if !ask_confirmation()? {
|
||||||
|
return Err("Operation aborted".into());
|
||||||
|
}
|
||||||
|
|
||||||
let mut child = Command::new(PACKAGE_MANAGER)
|
let noconfirm = if noconfirm {
|
||||||
.arg("--color")
|
"--noconfirm"
|
||||||
.arg("always")
|
} else {
|
||||||
.arg("-Syu")
|
"--confirm"
|
||||||
.arg(noconfirm)
|
};
|
||||||
.spawn()
|
|
||||||
.expect("Failed to execute command");
|
|
||||||
|
|
||||||
let status = child.wait().expect("Failed to wait on child");
|
let mut child = Command::new(PACKAGE_MANAGER)
|
||||||
|
.arg("--color")
|
||||||
|
.arg("always")
|
||||||
|
.arg("-Syu")
|
||||||
|
.arg(noconfirm)
|
||||||
|
.spawn()
|
||||||
|
.expect("Failed to execute command");
|
||||||
|
|
||||||
if !status.success() {
|
let status = child.wait().expect("Failed to wait on child");
|
||||||
return Err("Failed to upgrade packages".into());
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("{} {}", "::".bold().green(), "Packages upgraded".bold());
|
if !status.success() {
|
||||||
Ok(())
|
return Err("Failed to upgrade packages".into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println!("{} {}", "::".bold().green(), "Packages upgraded".bold());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user