mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2025-12-11 22:10:09 +01:00
chore: cleanup
This commit is contained in:
parent
f47bf23f6a
commit
2c7866baf2
6 changed files with 25 additions and 21 deletions
19
src/modes.rs
19
src/modes.rs
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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}");
|
||||
|
|
|
|||
|
|
@ -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> {
|
||||
|
|
|
|||
|
|
@ -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"];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue