From 9e93a085fd270c40582b60843b8ad7b92cd0701c Mon Sep 17 00:00:00 2001 From: Wataru Otsubo Date: Tue, 10 Sep 2024 21:07:50 +0900 Subject: [PATCH] refactor: split func for printing boards for retest --- src/main.rs | 11 ++--------- src/masterlog.rs | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index 74abb8f..8338576 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ use core::str; use std::{ fmt::Display, fs::File, - io::{BufRead, BufReader}, + io::{self, BufRead, BufReader}, path::{self, PathBuf}, str::FromStr, }; @@ -369,14 +369,7 @@ fn main() -> Result<()> { debug!("{:?}", result); // Print boards to retest - for (pos, boardresult) in &result.board_results { - if let Some(reason) = boardresult.is_need_retest() { - println!( - "Board {} at {} need retest for {}", - boardresult.id.id, pos, reason - ); - } - } + result.print_boards_to_retest(io::stdout())?; let outfile = outfile.unwrap_or(get_output_filename(&result)); diff --git a/src/masterlog.rs b/src/masterlog.rs index 8052778..6db76d8 100644 --- a/src/masterlog.rs +++ b/src/masterlog.rs @@ -1,4 +1,9 @@ -use std::{collections::BTreeMap, io::BufRead, path::PathBuf, str::FromStr}; +use std::{ + collections::BTreeMap, + io::{BufRead, Write}, + path::PathBuf, + str::FromStr, +}; use anyhow::{anyhow, Context, Result}; use chrono::{DateTime, Utc}; @@ -301,6 +306,19 @@ impl MasterLogResult { filename, }) } + + pub fn print_boards_to_retest(&self, mut wtr: impl Write) -> Result<()> { + for (pos, boardresult) in &self.board_results { + if let Some(reason) = boardresult.is_need_retest() { + writeln!( + wtr, + "Board {} at {} need retest for {}", + boardresult.id.id, pos, reason + )?; + } + } + Ok(()) + } } pub fn get_output_filename(result: &MasterLogResult) -> PathBuf {