mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2026-02-02 15:45:11 +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,
|
Some(packages) => packages,
|
||||||
None => {
|
None => {
|
||||||
eprintln!(
|
eprintln!("{}: {}", "pay-respects".red(), t!("package-not-found"));
|
||||||
"{}: {}",
|
|
||||||
"pay-respects".red(),
|
|
||||||
t!("package-not-found")
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let style = ui::Styled::default();
|
let style = ui::Styled::default();
|
||||||
let render_config = ui::RenderConfig::default()
|
let render_config = ui::RenderConfig::default().with_prompt_prefix(style);
|
||||||
.with_prompt_prefix(style);
|
let msg = format!("{}", t!("install-package")).bold().blue();
|
||||||
let msg = format!("{}", t!("install-package"))
|
|
||||||
.bold()
|
|
||||||
.blue();
|
|
||||||
let hint = format!(
|
let hint = format!(
|
||||||
"{} {} {}",
|
"{} {} {}",
|
||||||
"[↑/↓]".blue(),
|
"[↑/↓]".blue(),
|
||||||
|
|
@ -125,7 +117,8 @@ pub fn cnf(data: &mut Data) {
|
||||||
.without_help_message()
|
.without_help_message()
|
||||||
.with_render_config(render_config)
|
.with_render_config(render_config)
|
||||||
.without_filtering()
|
.without_filtering()
|
||||||
.prompt().unwrap();
|
.prompt()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// retry after installing package
|
// retry after installing package
|
||||||
if system::install_package(&shell, &package_manager, &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 function = match_list.join(",");
|
||||||
let (_, args) = eval_placeholder(&function, "{{shell", "}}");
|
let (_, args) = eval_placeholder(&function, "{{shell", "}}");
|
||||||
let function = &function[args.to_owned()].trim_matches(|c| c == '(' || c == ')');
|
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 {
|
} else {
|
||||||
suggest_typo(&split_command[index], match_list, executables)
|
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: Value = {
|
||||||
let json = serde_json::from_str(&res);
|
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);
|
eprintln!("Failed to parse JSON response: {}", res);
|
||||||
return None;
|
return None;
|
||||||
} else {
|
|
||||||
json.unwrap()
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ fn eval_condition(
|
||||||
last_command: &str,
|
last_command: &str,
|
||||||
error_msg: &str,
|
error_msg: &str,
|
||||||
split_command: &[String],
|
split_command: &[String],
|
||||||
data: &mut Data
|
data: &mut Data,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
match condition {
|
match condition {
|
||||||
"executable" => data.has_executable(arg),
|
"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();
|
let mut suggest = suggest.to_owned();
|
||||||
if suggest.contains("{{command}}") {
|
if suggest.contains("{{command}}") {
|
||||||
suggest = suggest.replace("{{command}}", "{last_command}");
|
suggest = suggest.replace("{{command}}", "{last_command}");
|
||||||
|
|
|
||||||
|
|
@ -284,7 +284,8 @@ pub fn expand_alias(map: &HashMap<String, String>, command: &str) -> Option<Stri
|
||||||
} else {
|
} else {
|
||||||
(command, "")
|
(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> {
|
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::io::stderr;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::process::Stdio;
|
use std::process::Stdio;
|
||||||
use crate::shell::Data;
|
|
||||||
|
|
||||||
pub fn get_package_manager(data: &mut Data) -> Option<String> {
|
pub fn get_package_manager(data: &mut Data) -> Option<String> {
|
||||||
let package_managers = vec!["pacman"];
|
let package_managers = vec!["pacman"];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue