[F] Prioritize CLI-specified ASCII art by reading it early to prevent file descriptor issues and ensure it overrides configuration. (#475)

This commit is contained in:
Azalea 2026-02-11 20:57:49 -05:00
parent 25824da0e0
commit abcc1d265b

View file

@ -52,6 +52,16 @@ fn main() -> Result<()> {
let options = options().run(); let options = options().run();
// Read ascii file first to avoid any issues with file descriptors being closed by other operations, and to allow CLI arguments to override config. (https://github.com/hykilpikonna/hyfetch/issues/475)
let cli_ascii = if let Some(path) = &options.ascii_file {
Some(RawAsciiArt {
asc: fs::read_to_string(path).with_context(|| format!("failed to read ascii from {path:?}"))?,
fg: Vec::new(),
})
} else {
None
};
let debug_mode = options.debug; let debug_mode = options.debug;
init_tracing_subsriber(debug_mode).context("failed to init tracing subscriber")?; init_tracing_subsriber(debug_mode).context("failed to init tracing subscriber")?;
@ -177,19 +187,15 @@ fn main() -> Result<()> {
}; };
debug!(?color_profile, "lightened color profile"); debug!(?color_profile, "lightened color profile");
let asc = if let Some(path_str) = config.custom_ascii_path { let asc = if let Some(asc) = cli_ascii {
asc
} else if let Some(path_str) = config.custom_ascii_path {
let path = PathBuf::from(path_str); let path = PathBuf::from(path_str);
RawAsciiArt { RawAsciiArt {
asc: fs::read_to_string(&path) asc: fs::read_to_string(&path)
.with_context(|| format!("failed to read ascii from {path:?}"))?, .with_context(|| format!("failed to read ascii from {path:?}"))?,
fg: Vec::new(), fg: Vec::new(),
} }
} else if let Some(path) = options.ascii_file {
RawAsciiArt {
asc: fs::read_to_string(&path)
.with_context(|| format!("failed to read ascii from {path:?}"))?,
fg: Vec::new(),
}
} else { } else {
get_distro_ascii(distro, backend).context("failed to get distro ascii")? get_distro_ascii(distro, backend).context("failed to get distro ascii")?
}; };