chore: cleanup

This commit is contained in:
iff 2024-12-07 17:15:52 +01:00
parent f47bf23f6a
commit 2c7866baf2
6 changed files with 25 additions and 21 deletions

View file

@ -93,25 +93,17 @@ pub fn cnf(data: &mut Data) {
}
};
let packages = match system::get_packages(&shell, &package_manager, executable)
{
let packages = match system::get_packages(&shell, &package_manager, executable) {
Some(packages) => packages,
None => {
eprintln!(
"{}: {}",
"pay-respects".red(),
t!("package-not-found")
);
eprintln!("{}: {}", "pay-respects".red(), t!("package-not-found"));
return;
}
};
let style = ui::Styled::default();
let render_config = ui::RenderConfig::default()
.with_prompt_prefix(style);
let msg = format!("{}", t!("install-package"))
.bold()
.blue();
let render_config = ui::RenderConfig::default().with_prompt_prefix(style);
let msg = format!("{}", t!("install-package")).bold().blue();
let hint = format!(
"{} {} {}",
"[↑/↓]".blue(),
@ -125,7 +117,8 @@ pub fn cnf(data: &mut Data) {
.without_help_message()
.with_render_config(render_config)
.without_filtering()
.prompt().unwrap();
.prompt()
.unwrap();
// retry after installing package
if system::install_package(&shell, &package_manager, &package) {

View file

@ -160,7 +160,11 @@ pub fn typo(suggest: &mut String, split_command: &[String], executables: &[Strin
let function = match_list.join(",");
let (_, args) = eval_placeholder(&function, "{{shell", "}}");
let function = &function[args.to_owned()].trim_matches(|c| c == '(' || c == ')');
suggest_typo(&split_command[index], eval_shell_command(shell, function), executables)
suggest_typo(
&split_command[index],
eval_shell_command(shell, function),
executables,
)
} else {
suggest_typo(&split_command[index], match_list, executables)
};

View file

@ -162,11 +162,11 @@ The command `{last_command}` returns the following error message: `{error_msg}`.
}
let json: Value = {
let json = serde_json::from_str(&res);
if json.is_err() {
if let Ok(json) = json {
json
} else {
eprintln!("Failed to parse JSON response: {}", res);
return None;
} else {
json.unwrap()
}
};

View file

@ -102,7 +102,7 @@ fn eval_condition(
last_command: &str,
error_msg: &str,
split_command: &[String],
data: &mut Data
data: &mut Data,
) -> bool {
match condition {
"executable" => data.has_executable(arg),
@ -116,7 +116,13 @@ fn eval_condition(
}
}
fn eval_suggest(suggest: &str, last_command: &str, error_msg: &str, executables: &[String], shell: &str) -> String {
fn eval_suggest(
suggest: &str,
last_command: &str,
error_msg: &str,
executables: &[String],
shell: &str,
) -> String {
let mut suggest = suggest.to_owned();
if suggest.contains("{{command}}") {
suggest = suggest.replace("{{command}}", "{last_command}");

View file

@ -284,7 +284,8 @@ pub fn expand_alias(map: &HashMap<String, String>, command: &str) -> Option<Stri
} else {
(command, "")
};
map.get(command).map(|expand| format!("{} {}", expand, args))
map.get(command)
.map(|expand| format!("{} {}", expand, args))
}
pub fn expand_alias_multiline(map: &HashMap<String, String>, command: &str) -> Option<String> {

View file

@ -1,7 +1,7 @@
use crate::shell::Data;
use std::io::stderr;
use std::process::Command;
use std::process::Stdio;
use crate::shell::Data;
pub fn get_package_manager(data: &mut Data) -> Option<String> {
let package_managers = vec!["pacman"];