From 5c3a3bbad71e21e845a869cb4e8257d83f0db612 Mon Sep 17 00:00:00 2001 From: joe-prosser Date: Thu, 25 Jul 2024 11:18:09 +0100 Subject: [PATCH] fix(commands): only create attachments dir when needed (#290) * fix(commands): only create attachments dir when needed Co-authored-by: Tom Milligan --------- Co-authored-by: Tom Milligan --- cli/src/commands/get/comments.rs | 37 ++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/cli/src/commands/get/comments.rs b/cli/src/commands/get/comments.rs index bea097e..73155ee 100644 --- a/cli/src/commands/get/comments.rs +++ b/cli/src/commands/get/comments.rs @@ -250,7 +250,7 @@ struct OutputLocations { attachments_dir: Option, } -fn get_output_locations(path: &Option) -> Result { +fn get_output_locations(path: &Option, attachments: bool) -> Result { if let Some(path) = path { let jsonl_file = Some( File::create(path) @@ -258,23 +258,28 @@ fn get_output_locations(path: &Option) -> Result { .map(BufWriter::new)?, ); - let attachments_dir = path - .parent() - .context("Could not get attachments directory")? - .join(format!( - "{0}.attachments", - path.file_name() - .context("Could not get output file name")? - .to_string_lossy() - )); - - if !attachments_dir.exists() { - create_dir(&attachments_dir)?; - } + let attachments_dir = if attachments { + let attachments_dir = path + .parent() + .context("Could not get attachments directory")? + .join(format!( + "{0}.attachments", + path.file_name() + .context("Could not get output file name")? + .to_string_lossy() + )); + + if !attachments_dir.exists() { + create_dir(&attachments_dir)?; + } + Some(attachments_dir) + } else { + None + }; Ok(OutputLocations { jsonl_file, - attachments_dir: Some(attachments_dir), + attachments_dir, }) } else { Ok(OutputLocations::default()) @@ -360,7 +365,7 @@ pub fn get_many(client: &Client, args: &GetManyCommentsArgs) -> Result<()> { let OutputLocations { jsonl_file, attachments_dir, - } = get_output_locations(path)?; + } = get_output_locations(path, include_attachment_content.unwrap_or_default())?; let mut label_attribute_filter: Option = None; if let (Some(dataset_id), Some(filter)) = (dataset, label_filter) {