error : valeur par défaut pour le nom du programme

This commit is contained in:
Ahurac 2024-04-14 18:49:09 +02:00
parent 85a8aa40b4
commit 701643848a

View file

@ -1,7 +1,9 @@
use std::env;
use std::fmt::{Display, Formatter, Result};
use std::path::Path; use std::path::Path;
pub fn print_error(message: &str) { pub fn print_error(message: &str) {
let name = std::env::args().next().unwrap(); let name = env::args().next().unwrap_or(String::from("rash"));
let name = Path::new(&name).file_name().unwrap().to_str().unwrap(); let name = Path::new(&name).file_name().unwrap().to_str().unwrap();
eprintln!("{}: {}", name, message); eprintln!("{}: {}", name, message);