fix: clippy and rm old code
This commit is contained in:
+3
-12
@@ -4,9 +4,9 @@ use clap::{ArgAction, Parser, Subcommand};
|
||||
#[command(version, about, long_about = None)]
|
||||
#[command(styles = get_clap_styles())]
|
||||
pub struct Args {
|
||||
/// Skips certain confirmation steps.
|
||||
#[arg(long = "confirm", action = ArgAction::SetTrue)]
|
||||
#[arg(long = "noconfirm", action = ArgAction::SetFalse, overrides_with = "confirm")]
|
||||
/// Skips certain non-interactive confirmation steps.
|
||||
#[arg(long = "confirm", action = ArgAction::SetTrue, global = true)]
|
||||
#[arg(long = "noconfirm", action = ArgAction::SetFalse, overrides_with = "confirm", global = true)]
|
||||
pub confirm: bool,
|
||||
|
||||
#[command(subcommand)]
|
||||
@@ -18,15 +18,6 @@ pub enum Command {
|
||||
/// Looks for `.pacnew` and `.pacsave` files and allows editing of them using `$EDITOR -d <file>
|
||||
/// <pacfile>`.
|
||||
Pacfiles,
|
||||
|
||||
// Pacfiles {
|
||||
// /// Override of `PACMAN_AUTH`.
|
||||
// #[arg(short, long)]
|
||||
// auth: Option<String>,
|
||||
// },
|
||||
|
||||
// Dummy argument to start working
|
||||
Dummy,
|
||||
}
|
||||
|
||||
const fn get_clap_styles() -> clap::builder::Styles {
|
||||
|
||||
-17
@@ -1,7 +1,5 @@
|
||||
#![feature(iterator_try_collect, once_cell_try)]
|
||||
|
||||
use std::io::Write;
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
mod args;
|
||||
@@ -9,27 +7,12 @@ mod commands;
|
||||
mod sys;
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
// if unsafe { libc::geteuid() } == 0 {
|
||||
// return Err(anyhow::anyhow!(
|
||||
// "the program is not designed to runn as root, priviledge escalation is done by the program itself"
|
||||
// ));
|
||||
// }
|
||||
|
||||
let args = args::Args::parse();
|
||||
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("trace"))
|
||||
// .format(|buf, record| {
|
||||
// writeln!(
|
||||
// buf,
|
||||
// "{}: {}",
|
||||
// record.level(),
|
||||
// record.args()
|
||||
// )
|
||||
// })
|
||||
.format_timestamp(None)
|
||||
.init();
|
||||
|
||||
match args.subcommand {
|
||||
args::Command::Pacfiles => commands::pacfiles(&args),
|
||||
args::Command::Dummy => unimplemented!(),
|
||||
}
|
||||
}
|
||||
|
||||
+34
-34
@@ -1,38 +1,38 @@
|
||||
use std::{
|
||||
io,
|
||||
process::{Command, Stdio},
|
||||
sync::OnceLock,
|
||||
};
|
||||
// use std::{
|
||||
// io,
|
||||
// process::{Command, Stdio},
|
||||
// sync::OnceLock,
|
||||
// };
|
||||
|
||||
pub fn get_auth() -> io::Result<&'static [String]> {
|
||||
pub fn get_auth() -> io::Result<Vec<String>> {
|
||||
let mut cmd = Command::new("bash");
|
||||
let output = cmd
|
||||
.args([
|
||||
"-euo",
|
||||
"pipefail",
|
||||
"-c",
|
||||
"source /etc/makepkg.conf && \
|
||||
printf \"%s\\0\" \"${PACMAN_AUTH[@]}\"",
|
||||
])
|
||||
.stdout(Stdio::piped())
|
||||
.output()?;
|
||||
// pub fn get_auth() -> io::Result<&'static [String]> {
|
||||
// pub fn get_auth() -> io::Result<Vec<String>> {
|
||||
// let mut cmd = Command::new("bash");
|
||||
// let output = cmd
|
||||
// .args([
|
||||
// "-euo",
|
||||
// "pipefail",
|
||||
// "-c",
|
||||
// "source /etc/makepkg.conf && \
|
||||
// printf \"%s\\0\" \"${PACMAN_AUTH[@]}\"",
|
||||
// ])
|
||||
// .stdout(Stdio::piped())
|
||||
// .output()?;
|
||||
|
||||
if output.status.success() {
|
||||
output
|
||||
.stdout
|
||||
.split(|&b| b == b'\0')
|
||||
.filter(|slice| !slice.is_empty())
|
||||
.map(Vec::from)
|
||||
.map(String::from_utf8)
|
||||
.try_collect()
|
||||
.map_err(io::Error::other)
|
||||
} else {
|
||||
Err(io::Error::other("bash failed to source /etc/makepkg.conf"))
|
||||
}
|
||||
}
|
||||
// if output.status.success() {
|
||||
// output
|
||||
// .stdout
|
||||
// .split(|&b| b == b'\0')
|
||||
// .filter(|slice| !slice.is_empty())
|
||||
// .map(Vec::from)
|
||||
// .map(String::from_utf8)
|
||||
// .try_collect()
|
||||
// .map_err(io::Error::other)
|
||||
// } else {
|
||||
// Err(io::Error::other("bash failed to source /etc/makepkg.conf"))
|
||||
// }
|
||||
// }
|
||||
|
||||
static PACMAN_AUTH_CELL: OnceLock<Vec<String>> = const { OnceLock::new() };
|
||||
// static PACMAN_AUTH_CELL: OnceLock<Vec<String>> = const { OnceLock::new() };
|
||||
|
||||
PACMAN_AUTH_CELL.get_or_try_init(get_auth).map(|v| v as &[_])
|
||||
}
|
||||
// PACMAN_AUTH_CELL.get_or_try_init(get_auth).map(|v| v as &[_])
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user