diff --git a/CHANGELOG.md b/CHANGELOG.md index d552b8d..a19a426 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Use `out_.csv` as default output path + ## [1.0.1] ### Fixed diff --git a/src/main.rs b/src/main.rs index 73f24c6..74abb8f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,7 +11,7 @@ use anyhow::{anyhow, Context, Result}; use chrono::{DateTime, Utc}; use clap::{Parser, Subcommand}; use log::{debug, error, info, trace, warn}; -use masterlog::MasterLogResult; +use masterlog::{get_output_filename, MasterLogResult}; use semver::Version; use serde::{Deserialize, Serialize}; use serde_with::{serde_as, DisplayFromStr}; @@ -36,8 +36,9 @@ pub enum Commands { /// Master log file. master_log: path::PathBuf, /// Output CSV file. + /// Default is `out_.csv` // #[arg(default_value = get_default_log_path().into_os_string())] - outfile: PathBuf, + outfile: Option, }, /// Check CSV format CheckDB { @@ -377,6 +378,8 @@ fn main() -> Result<()> { } } + let outfile = outfile.unwrap_or(get_output_filename(&result)); + let expanded_results = PsbQaqcResult::from_masterlogresult(result); let mut wtr = match outfile.exists() { diff --git a/src/masterlog.rs b/src/masterlog.rs index 67d684b..8052778 100644 --- a/src/masterlog.rs +++ b/src/masterlog.rs @@ -1,4 +1,4 @@ -use std::{collections::BTreeMap, io::BufRead, str::FromStr}; +use std::{collections::BTreeMap, io::BufRead, path::PathBuf, str::FromStr}; use anyhow::{anyhow, Context, Result}; use chrono::{DateTime, Utc}; @@ -6,7 +6,7 @@ use log::{debug, info, trace}; use regex::Regex; use semver::Version; -use crate::{Position, PositionLayer, PsbId}; +use crate::{Position, PositionLayer, PsbId, PsbQaqcResult}; /// QAQC results for each boards extracted from master log. /// @@ -303,6 +303,10 @@ impl MasterLogResult { } } +pub fn get_output_filename(result: &MasterLogResult) -> PathBuf { + PathBuf::from(format!("out_{}.csv", result.runid)) +} + #[cfg(test)] mod test { use semver::Version; diff --git a/tests/cli.rs b/tests/cli.rs index cae07cf..1ed54d2 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -1,11 +1,13 @@ mod integrated_test { use std::{ - fs::File, + env::current_dir, + ffi::OsString, + fs::{self, read_dir, File}, io::{BufRead, BufReader}, path::PathBuf, }; - use anyhow::Result; + use anyhow::{Context, Result}; use assert_cmd::Command; use itertools::Itertools; use predicates::prelude::*; @@ -67,17 +69,28 @@ mod integrated_test { #[test] fn partial_log() -> Result<()> { let test_out_dir = assert_fs::TempDir::new()?; - let test_out = PathBuf::new().join(&test_out_dir).join("out.csv"); + fs::copy( + "./tests/example_logs/valid/84.log", + test_out_dir.join("84.log"), + ) + .context("Error preparing source file")?; let mut cmd = Command::cargo_bin("psb-qaqc")?; - cmd.current_dir("tests") + cmd.current_dir(&test_out_dir) .arg("add-master-log") - .arg("./example_logs/valid/84.log") - .arg(test_out.as_path()) + .arg("84.log") .assert() .success() .stdout(predicate::str::contains("Creating new file")); + assert!(read_dir(&test_out_dir) + .context("Failed to read dir")? + .any(|entry| { + entry + .map_or(OsString::from(""), |entry| entry.file_name()) + .eq("out_84.csv") + })); + Ok(()) } }