dmesg: parse time-format command line argument.

This commit is contained in:
Fuad Ismail
2024-11-25 13:26:35 +07:00
parent c893226fe8
commit 49bd8ead50

View File

@@ -27,6 +27,22 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
if matches.get_flag(options::JSON) {
dmesg.output_format = OutputFormat::Json;
}
if let Some(time_format) = matches.get_one::<String>(options::TIME_FORMAT) {
match &time_format[..] {
"delta" => dmesg.time_format = TimeFormat::Delta,
"reltime" => dmesg.time_format = TimeFormat::Reltime,
"ctime" => dmesg.time_format = TimeFormat::Ctime,
"notime" => dmesg.time_format = TimeFormat::Notime,
"iso" => dmesg.time_format = TimeFormat::Iso,
"raw" => dmesg.time_format = TimeFormat::Raw,
_ => {
return Err(USimpleError::new(
1,
format!("unknown time format: {time_format}"),
))
}
}
}
dmesg.parse()?.print();
Ok(())
}
@@ -159,6 +175,7 @@ enum TimeFormat {
Delta,
Reltime,
Ctime,
Notime,
Iso,
Raw,
}