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
b87f22975e
commit
1577ce400e
3 changed files with 28 additions and 25 deletions
|
|
@ -1,7 +1,6 @@
|
||||||
use crate::shell::{initialization, Init};
|
use crate::shell::{initialization, Init};
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
|
|
||||||
|
|
||||||
pub enum Status {
|
pub enum Status {
|
||||||
Continue,
|
Continue,
|
||||||
Exit, // version, help, etc.
|
Exit, // version, help, etc.
|
||||||
|
|
|
||||||
|
|
@ -226,7 +226,7 @@ pub fn command_output(shell: &str, command: &str) -> String {
|
||||||
.output()
|
.output()
|
||||||
.expect("failed to execute process");
|
.expect("failed to execute process");
|
||||||
|
|
||||||
String::from_utf8_lossy(&output.stdout).to_string()
|
String::from_utf8_lossy(&output.stdout).to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn last_command(shell: &str) -> String {
|
pub fn last_command(shell: &str) -> String {
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,11 @@
|
||||||
use crate::shell::{Data, command_output, elevate};
|
use crate::shell::{command_output, elevate, 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;
|
||||||
|
|
||||||
pub fn get_package_manager(data: &mut Data) -> Option<String> {
|
pub fn get_package_manager(data: &mut Data) -> Option<String> {
|
||||||
let package_managers = vec![
|
let package_managers = vec![
|
||||||
"apt",
|
"apt", "dnf", "emerge", "nix", "pacman",
|
||||||
"dnf",
|
|
||||||
"emerge",
|
|
||||||
"nix",
|
|
||||||
"pacman",
|
|
||||||
// "pkg",
|
// "pkg",
|
||||||
// "yum",
|
// "yum",
|
||||||
// "zypper",
|
// "zypper",
|
||||||
|
|
@ -23,7 +19,11 @@ pub fn get_package_manager(data: &mut Data) -> Option<String> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_packages(data: &mut Data, package_manager: &str, executable: &str) -> Option<Vec<String>> {
|
pub fn get_packages(
|
||||||
|
data: &mut Data,
|
||||||
|
package_manager: &str,
|
||||||
|
executable: &str,
|
||||||
|
) -> Option<Vec<String>> {
|
||||||
let shell = &data.shell.clone();
|
let shell = &data.shell.clone();
|
||||||
match package_manager {
|
match package_manager {
|
||||||
"apt" => {
|
"apt" => {
|
||||||
|
|
@ -32,7 +32,7 @@ pub fn get_packages(data: &mut Data, package_manager: &str, executable: &str) ->
|
||||||
}
|
}
|
||||||
let result = command_output(shell, &format!("dpkg -S '*/bin/{}'", executable));
|
let result = command_output(shell, &format!("dpkg -S '*/bin/{}'", executable));
|
||||||
if result.is_empty() {
|
if result.is_empty() {
|
||||||
return None
|
return None;
|
||||||
}
|
}
|
||||||
let packages: Vec<String> = result
|
let packages: Vec<String> = result
|
||||||
.lines()
|
.lines()
|
||||||
|
|
@ -44,11 +44,11 @@ pub fn get_packages(data: &mut Data, package_manager: &str, executable: &str) ->
|
||||||
} else {
|
} else {
|
||||||
Some(packages)
|
Some(packages)
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
"dnf" => {
|
"dnf" => {
|
||||||
let result = command_output(shell, &format!("dnf provides {}", executable));
|
let result = command_output(shell, &format!("dnf provides {}", executable));
|
||||||
if result.is_empty() {
|
if result.is_empty() {
|
||||||
return None
|
return None;
|
||||||
}
|
}
|
||||||
let packages: Vec<String> = result
|
let packages: Vec<String> = result
|
||||||
.lines()
|
.lines()
|
||||||
|
|
@ -59,14 +59,14 @@ pub fn get_packages(data: &mut Data, package_manager: &str, executable: &str) ->
|
||||||
} else {
|
} else {
|
||||||
Some(packages)
|
Some(packages)
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
"emerge" => {
|
"emerge" => {
|
||||||
if !data.has_executable("e-file") {
|
if !data.has_executable("e-file") {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let result = command_output(shell, &format!("e-file /usr/bin/{}", executable));
|
let result = command_output(shell, &format!("e-file /usr/bin/{}", executable));
|
||||||
if result.is_empty() {
|
if result.is_empty() {
|
||||||
return None
|
return None;
|
||||||
}
|
}
|
||||||
let mut packages = vec![];
|
let mut packages = vec![];
|
||||||
for line in result.lines() {
|
for line in result.lines() {
|
||||||
|
|
@ -79,22 +79,26 @@ pub fn get_packages(data: &mut Data, package_manager: &str, executable: &str) ->
|
||||||
} else {
|
} else {
|
||||||
Some(packages)
|
Some(packages)
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
"nix" => {
|
"nix" => {
|
||||||
if !data.has_executable("nix-locate") {
|
if !data.has_executable("nix-locate") {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let result = command_output(shell, &format!("nix-locate 'bin/{}'", executable));
|
let result = command_output(shell, &format!("nix-locate 'bin/{}'", executable));
|
||||||
if result.is_empty() {
|
if result.is_empty() {
|
||||||
return None
|
return None;
|
||||||
}
|
}
|
||||||
let packages: Vec<String> = result
|
let packages: Vec<String> = result
|
||||||
.lines()
|
.lines()
|
||||||
.map(|line| line
|
.map(|line| {
|
||||||
.split_whitespace()
|
line.split_whitespace()
|
||||||
.next().unwrap()
|
.next()
|
||||||
.rsplit_once('.')
|
.unwrap()
|
||||||
.unwrap().0.to_string())
|
.rsplit_once('.')
|
||||||
|
.unwrap()
|
||||||
|
.0
|
||||||
|
.to_string()
|
||||||
|
})
|
||||||
.collect();
|
.collect();
|
||||||
if packages.is_empty() {
|
if packages.is_empty() {
|
||||||
None
|
None
|
||||||
|
|
@ -105,11 +109,11 @@ pub fn get_packages(data: &mut Data, package_manager: &str, executable: &str) ->
|
||||||
"pacman" => {
|
"pacman" => {
|
||||||
let result = if data.has_executable("pkgfile") {
|
let result = if data.has_executable("pkgfile") {
|
||||||
command_output(shell, &format!("pkgfile -b {}", executable))
|
command_output(shell, &format!("pkgfile -b {}", executable))
|
||||||
} else{
|
} else {
|
||||||
command_output(shell, &format!("pacman -Fq /usr/bin/{}", executable))
|
command_output(shell, &format!("pacman -Fq /usr/bin/{}", executable))
|
||||||
};
|
};
|
||||||
if result.is_empty() {
|
if result.is_empty() {
|
||||||
return None
|
return None;
|
||||||
}
|
}
|
||||||
let packages: Vec<String> = result
|
let packages: Vec<String> = result
|
||||||
.lines()
|
.lines()
|
||||||
|
|
@ -120,7 +124,7 @@ pub fn get_packages(data: &mut Data, package_manager: &str, executable: &str) ->
|
||||||
} else {
|
} else {
|
||||||
Some(packages)
|
Some(packages)
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
_ => unreachable!("Unsupported package manager"),
|
_ => unreachable!("Unsupported package manager"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue