From 974c4514b2bfb4c3ecd0dc55cbcd0bf7bd097a58 Mon Sep 17 00:00:00 2001 From: Teoh Han Hui Date: Fri, 28 Jun 2024 05:09:32 +0800 Subject: [PATCH] Fix distro overriding --- crates/hyfetch/src/bin/hyfetch.rs | 2 +- crates/hyfetch/src/cli_options.rs | 6 +++--- crates/hyfetch/src/neofetch_util.rs | 20 +++++++++++++------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/crates/hyfetch/src/bin/hyfetch.rs b/crates/hyfetch/src/bin/hyfetch.rs index ae49e940..c6dacab3 100644 --- a/crates/hyfetch/src/bin/hyfetch.rs +++ b/crates/hyfetch/src/bin/hyfetch.rs @@ -15,7 +15,7 @@ fn main() -> Result<()> { if options.test_print { println!( "{}", - get_distro_ascii(None).context("Failed to get distro ascii")? + get_distro_ascii(options.distro.as_ref()).context("Failed to get distro ascii")? ); return Ok(()); } diff --git a/crates/hyfetch/src/cli_options.rs b/crates/hyfetch/src/cli_options.rs index 9910bcd0..71c8e9a7 100644 --- a/crates/hyfetch/src/cli_options.rs +++ b/crates/hyfetch/src/cli_options.rs @@ -23,7 +23,7 @@ pub struct Options { pub colors_use_overlay: bool, pub june: bool, pub debug: bool, - pub test_distro: Option, + pub distro: Option, pub ascii_file: Option, pub test_print: bool, pub ask_exit: bool, @@ -103,7 +103,7 @@ BACKEND={{{}}}", .help("Test for a specific distro") .argument("DISTRO") .optional(); - let test_distro = construct!([distro, test_distro]); + let distro = construct!([distro, test_distro]); let ascii_file = long("ascii-file") .help("Use a specific file for the ascii art") .argument("ASCII_FILE"); @@ -131,7 +131,7 @@ BACKEND={{{}}}", colors_use_overlay, june, debug, - test_distro, + distro, ascii_file, // hidden test_print, diff --git a/crates/hyfetch/src/neofetch_util.rs b/crates/hyfetch/src/neofetch_util.rs index 5e27a7b3..051c1a0f 100644 --- a/crates/hyfetch/src/neofetch_util.rs +++ b/crates/hyfetch/src/neofetch_util.rs @@ -1,3 +1,4 @@ +use std::borrow::Cow; use std::ffi::OsStr; #[cfg(unix)] use std::os::unix::process::ExitStatusExt as _; @@ -44,16 +45,21 @@ pub fn get_command_path() -> Result { Err(anyhow!("neofetch command not found")) } +/// Gets the distro ascii of the current distro. Or if distro is specified, get +/// the specific distro's ascii art instead. #[tracing::instrument(level = "debug")] -pub fn get_distro_ascii(distro: Option) -> Result { - // TODO - - let distro = if let Some(distro) = distro { - distro +pub fn get_distro_ascii(distro: Option) -> Result +where + S: AsRef + fmt::Debug, +{ + let distro: Cow<_> = if let Some(distro) = distro.as_ref() { + distro.as_ref().into() } else { - get_distro_name().context("Failed to get distro name")? + get_distro_name() + .context("Failed to get distro name")? + .into() }; - debug!(distro, "resolved distro name"); + debug!(%distro, "distro name"); todo!() }