Skip to content

Commit

Permalink
Fix handle_no_result function with --no-progress flag
Browse files Browse the repository at this point in the history
  • Loading branch information
eatradish committed Oct 18, 2024
1 parent b93a294 commit 2cc5b7f
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 25 deletions.
34 changes: 30 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,14 @@ fn run_subcmd(matches: ArgMatches, dry_run: bool, no_progress: bool) -> Result<i
let all = args.get_flag("all");
let json = args.get_flag("json");

show::execute(all, input, sysroot, json, oma_args.another_apt_options)?
show::execute(
all,
input,
sysroot,
json,
oma_args.another_apt_options,
no_progress,
)?
}
Some(("search", args)) => {
let patterns = args
Expand Down Expand Up @@ -547,7 +554,14 @@ fn run_subcmd(matches: ArgMatches, dry_run: bool, no_progress: bool) -> Result<i
let pkgs = pkgs_getter(args).unwrap();
let dry_run = args.get_flag("dry_run");

mark::execute(op, pkgs, dry_run, sysroot, oma_args.another_apt_options)?
mark::execute(
op,
pkgs,
dry_run,
sysroot,
oma_args.another_apt_options,
no_progress,
)?
}
Some(("command-not-found", args)) => {
command_not_found::execute(args.get_one::<String>("package").unwrap())?
Expand Down Expand Up @@ -577,13 +591,25 @@ fn run_subcmd(matches: ArgMatches, dry_run: bool, no_progress: bool) -> Result<i
let pkgs = pkgs_getter(args).unwrap();
let json = args.get_flag("json");

depends::execute(pkgs, sysroot, json, oma_args.another_apt_options)?
depends::execute(
pkgs,
sysroot,
json,
oma_args.another_apt_options,
no_progress,
)?
}
Some(("rdepends", args)) => {
let pkgs = pkgs_getter(args).unwrap();
let json = args.get_flag("json");

rdepends::execute(pkgs, sysroot, json, oma_args.another_apt_options)?
rdepends::execute(
pkgs,
sysroot,
json,
oma_args.another_apt_options,
no_progress,
)?
}
Some(("clean", _)) => clean::execute(no_progress, sysroot, oma_args.another_apt_options)?,
Some(("history", _)) => subcommand::history::execute_history(sysroot)?,
Expand Down
3 changes: 2 additions & 1 deletion src/subcommand/depends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub fn execute(
sysroot: String,
json: bool,
another_apt_options: Vec<String>,
no_progress: bool,
) -> Result<i32, OutputError> {
for pkg in &pkgs {
check_unsupported_stmt(pkg);
Expand All @@ -30,7 +31,7 @@ pub fn execute(
false,
)?;

handle_no_result(sysroot, no_result)?;
handle_no_result(sysroot, no_result, no_progress)?;

if !json {
for pkg in pkgs {
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn execute(
let oma_apt_args = OmaAptArgs::builder().build();
let mut apt = OmaApt::new(vec![], oma_apt_args, dry_run, apt_config)?;
let (pkgs, no_result) = apt.select_pkg(&keyword, false, true, true)?;
handle_no_result("/", no_result)?;
handle_no_result("/", no_result, no_progress)?;

let progress_manager: &dyn DownloadProgressControl = if !no_progress {
&OmaMultiProgressBar::default()
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub fn execute_undo(
}

let (delete, no_result) = apt.select_pkg(&delete, false, true, false)?;
handle_no_result(&sysroot, no_result)?;
handle_no_result(&sysroot, no_result, no_progress)?;

apt.remove(&delete, false, true)?;

Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub fn execute(
}
}

handle_no_result(&args.sysroot, no_result)?;
handle_no_result(&args.sysroot, no_result, no_progress)?;

let request = CommitRequest {
apt,
Expand Down
3 changes: 2 additions & 1 deletion src/subcommand/mark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub fn execute(
dry_run: bool,
sysroot: String,
another_apt_options: Vec<String>,
no_progress: bool,
) -> Result<i32, OutputError> {
root()?;

Expand All @@ -39,7 +40,7 @@ pub fn execute(
false,
)?;

handle_no_result(sysroot, no_result)?;
handle_no_result(sysroot, no_result, no_progress)?;

apt.mark_install_status(pkgs, op == "auto", dry_run)?
.into_iter()
Expand Down
3 changes: 2 additions & 1 deletion src/subcommand/rdepends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub fn execute(
sysroot: String,
json: bool,
another_apt_options: Vec<String>,
no_progress: bool,
) -> Result<i32, OutputError> {
for pkg in &pkgs {
check_unsupported_stmt(pkg);
Expand All @@ -31,7 +32,7 @@ pub fn execute(
false,
)?;

handle_no_result(sysroot, no_result)?;
handle_no_result(sysroot, no_result, no_progress)?;

if !json {
for pkg in pkgs {
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn execute(
}
}

handle_no_result(&args.sysroot, no_result)?;
handle_no_result(&args.sysroot, no_result, no_progress)?;

let request = CommitRequest {
apt,
Expand Down
3 changes: 2 additions & 1 deletion src/subcommand/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ pub fn execute(
sysroot: String,
json: bool,
another_apt_options: Vec<String>,
no_progress: bool,
) -> Result<i32, OutputError> {
let oma_apt_args = OmaAptArgs::builder()
.another_apt_options(another_apt_options)
.sysroot(sysroot.clone())
.build();
let mut apt = OmaApt::new(vec![], oma_apt_args, false, AptConfig::new())?;
let (pkgs, no_result) = apt.select_pkg(&input, false, false, false)?;
handle_no_result(sysroot, no_result)?;
handle_no_result(sysroot, no_result, no_progress)?;

let mut stdout = stdout();

Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub fn execute(
}
}

handle_no_result(&args.sysroot, no_result)?;
handle_no_result(&args.sysroot, no_result, no_progress)?;

apt.resolve(false, true)?;

Expand Down
39 changes: 27 additions & 12 deletions src/subcommand/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,37 @@ use super::remove::ask_user_do_as_i_say;
pub(crate) fn handle_no_result(
sysroot: impl AsRef<Path>,
no_result: Vec<String>,
no_progress: bool,
) -> Result<(), OutputError> {
let mut bin = vec![];

let pb = OmaProgressBar::new_spinner(Some(fl!("searching")));
let pb = if !no_progress {
Some(OmaProgressBar::new_spinner(Some(fl!("searching"))))
} else {
None
};

for word in &no_result {
if word == "266" {
pb.writeln(
&style("ERROR").red().bold().to_string(),
"无法找到匹配关键字为艾露露的软件包",
)
.ok();
if let Some(ref pb) = pb {
pb.writeln(
&style("ERROR").red().bold().to_string(),
"无法找到匹配关键字为艾露露的软件包",
)
.ok();
} else {
error!("无法找到匹配关键字为艾露露的软件包");
}
} else {
pb.writeln(
&style("ERROR").red().bold().to_string(),
&fl!("could-not-find-pkg-from-keyword", c = word),
)
.ok();
if let Some(ref pb) = pb {
pb.writeln(
&style("ERROR").red().bold().to_string(),
&fl!("could-not-find-pkg-from-keyword", c = word),
)
.ok();
} else {
error!("{}", fl!("could-not-find-pkg-from-keyword", c = word));
}

contents_search(&sysroot, Mode::BinProvides, word, |(pkg, file)| {
if file == format!("/usr/bin/{}", word) {
Expand All @@ -83,7 +96,9 @@ pub(crate) fn handle_no_result(
})
.ok();

pb.inner.finish_and_clear();
if let Some(ref pb) = pb {
pb.inner.finish_and_clear();
}
}
}

Expand Down

0 comments on commit 2cc5b7f

Please sign in to comment.