dmesg: refactor to avoid duplicate code.
Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
This commit is contained in:
@ -28,20 +28,20 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||||||
dmesg.output_format = OutputFormat::Json;
|
dmesg.output_format = OutputFormat::Json;
|
||||||
}
|
}
|
||||||
if let Some(time_format) = matches.get_one::<String>(options::TIME_FORMAT) {
|
if let Some(time_format) = matches.get_one::<String>(options::TIME_FORMAT) {
|
||||||
match &time_format[..] {
|
dmesg.time_format = match &time_format[..] {
|
||||||
"delta" => dmesg.time_format = TimeFormat::Delta,
|
"delta" => TimeFormat::Delta,
|
||||||
"reltime" => dmesg.time_format = TimeFormat::Reltime,
|
"reltime" => TimeFormat::Reltime,
|
||||||
"ctime" => dmesg.time_format = TimeFormat::Ctime,
|
"ctime" => TimeFormat::Ctime,
|
||||||
"notime" => dmesg.time_format = TimeFormat::Notime,
|
"notime" => TimeFormat::Notime,
|
||||||
"iso" => dmesg.time_format = TimeFormat::Iso,
|
"iso" => TimeFormat::Iso,
|
||||||
"raw" => dmesg.time_format = TimeFormat::Raw,
|
"raw" => TimeFormat::Raw,
|
||||||
_ => {
|
_ => {
|
||||||
return Err(USimpleError::new(
|
return Err(USimpleError::new(
|
||||||
1,
|
1,
|
||||||
format!("unknown time format: {time_format}"),
|
format!("unknown time format: {time_format}"),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
dmesg.parse()?.print();
|
dmesg.parse()?.print();
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Reference in New Issue
Block a user