refactor: move RunType::execute to ExecutionContext

This commit is contained in:
Andre Toerien
2025-06-24 15:20:29 +02:00
committed by Gideon
parent 257d202646
commit 32197f79f3
27 changed files with 386 additions and 621 deletions

View File

@@ -33,13 +33,12 @@ pub struct YayParu {
impl ArchPackageManager for YayParu {
fn upgrade(&self, ctx: &ExecutionContext) -> Result<()> {
if ctx.config().show_arch_news() {
ctx.run_type()
.execute(&self.executable)
ctx.execute(&self.executable)
.arg("-Pw")
.status_checked_with_codes(&[1, 0])?;
}
let mut command = ctx.run_type().execute(&self.executable);
let mut command = ctx.execute(&self.executable);
command
.arg("--pacman")
@@ -54,7 +53,7 @@ impl ArchPackageManager for YayParu {
command.status_checked()?;
if ctx.config().cleanup() {
let mut command = ctx.run_type().execute(&self.executable);
let mut command = ctx.execute(&self.executable);
command.arg("--pacman").arg(&self.pacman).arg("-Scc");
if ctx.config().yes(Step::System) {
command.arg("--noconfirm");
@@ -81,7 +80,7 @@ pub struct GarudaUpdate {
impl ArchPackageManager for GarudaUpdate {
fn upgrade(&self, ctx: &ExecutionContext) -> Result<()> {
let mut command = ctx.run_type().execute(&self.executable);
let mut command = ctx.execute(&self.executable);
command
.env("PATH", get_execution_path())
@@ -112,7 +111,7 @@ pub struct Trizen {
impl ArchPackageManager for Trizen {
fn upgrade(&self, ctx: &ExecutionContext) -> Result<()> {
let mut command = ctx.run_type().execute(&self.executable);
let mut command = ctx.execute(&self.executable);
command
.arg("-Syu")
@@ -125,7 +124,7 @@ impl ArchPackageManager for Trizen {
command.status_checked()?;
if ctx.config().cleanup() {
let mut command = ctx.run_type().execute(&self.executable);
let mut command = ctx.execute(&self.executable);
command.arg("-Sc");
if ctx.config().yes(Step::System) {
command.arg("--noconfirm");
@@ -152,7 +151,7 @@ pub struct Pacman {
impl ArchPackageManager for Pacman {
fn upgrade(&self, ctx: &ExecutionContext) -> Result<()> {
let sudo = require_option(ctx.sudo().as_ref(), "sudo is required to run pacman".into())?;
let mut command = ctx.run_type().execute(sudo);
let mut command = ctx.execute(sudo);
command
.arg(&self.executable)
.arg("-Syu")
@@ -163,7 +162,7 @@ impl ArchPackageManager for Pacman {
command.status_checked()?;
if ctx.config().cleanup() {
let mut command = ctx.run_type().execute(sudo);
let mut command = ctx.execute(sudo);
command.arg(&self.executable).arg("-Scc");
if ctx.config().yes(Step::System) {
command.arg("--noconfirm");
@@ -197,7 +196,7 @@ impl Pikaur {
impl ArchPackageManager for Pikaur {
fn upgrade(&self, ctx: &ExecutionContext) -> Result<()> {
let mut command = ctx.run_type().execute(&self.executable);
let mut command = ctx.execute(&self.executable);
command
.arg("-Syu")
@@ -211,7 +210,7 @@ impl ArchPackageManager for Pikaur {
command.status_checked()?;
if ctx.config().cleanup() {
let mut command = ctx.run_type().execute(&self.executable);
let mut command = ctx.execute(&self.executable);
command.arg("-Sc");
if ctx.config().yes(Step::System) {
command.arg("--noconfirm");
@@ -236,7 +235,7 @@ impl Pamac {
}
impl ArchPackageManager for Pamac {
fn upgrade(&self, ctx: &ExecutionContext) -> Result<()> {
let mut command = ctx.run_type().execute(&self.executable);
let mut command = ctx.execute(&self.executable);
command
.arg("upgrade")
@@ -250,7 +249,7 @@ impl ArchPackageManager for Pamac {
command.status_checked()?;
if ctx.config().cleanup() {
let mut command = ctx.run_type().execute(&self.executable);
let mut command = ctx.execute(&self.executable);
command.arg("clean");
if ctx.config().yes(Step::System) {
command.arg("--no-confirm");
@@ -278,11 +277,7 @@ impl ArchPackageManager for Aura {
fn upgrade(&self, ctx: &ExecutionContext) -> Result<()> {
use semver::Version;
let version_cmd_output = ctx
.run_type()
.execute(&self.executable)
.arg("--version")
.output_checked_utf8()?;
let version_cmd_output = ctx.execute(&self.executable).arg("--version").output_checked_utf8()?;
// Output will be something like: "aura x.x.x\n"
let version_cmd_stdout = version_cmd_output.stdout;
let version_str = version_cmd_stdout.trim_start_matches("aura ").trim_end();
@@ -295,7 +290,7 @@ impl ArchPackageManager for Aura {
let version_no_sudo = Version::new(4, 0, 6);
if version >= version_no_sudo {
let mut cmd = ctx.run_type().execute(&self.executable);
let mut cmd = ctx.execute(&self.executable);
cmd.arg("-Au")
.args(ctx.config().aura_aur_arguments().split_whitespace());
if ctx.config().yes(Step::System) {
@@ -303,7 +298,7 @@ impl ArchPackageManager for Aura {
}
cmd.status_checked()?;
let mut cmd = ctx.run_type().execute(&self.executable);
let mut cmd = ctx.execute(&self.executable);
cmd.arg("-Syu")
.args(ctx.config().aura_pacman_arguments().split_whitespace());
if ctx.config().yes(Step::System) {
@@ -316,7 +311,7 @@ impl ArchPackageManager for Aura {
t!("Aura(<0.4.6) requires sudo installed to work with AUR packages").to_string(),
)?;
let mut cmd = ctx.run_type().execute(sudo);
let mut cmd = ctx.execute(sudo);
cmd.arg(&self.executable)
.arg("-Au")
.args(ctx.config().aura_aur_arguments().split_whitespace());
@@ -325,7 +320,7 @@ impl ArchPackageManager for Aura {
}
cmd.status_checked()?;
let mut cmd = ctx.run_type().execute(sudo);
let mut cmd = ctx.execute(sudo);
cmd.arg(&self.executable)
.arg("-Syu")
.args(ctx.config().aura_pacman_arguments().split_whitespace());