From b14b6ba525985b75c15e56fec78b3fe82a91993e Mon Sep 17 00:00:00 2001 From: Joe Prosser Date: Wed, 24 Jul 2024 20:59:47 +0100 Subject: [PATCH 1/2] fix(commands): only create attachments dir when needed --- 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..073f7ce 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.is_some_and(|v| v))?; let mut label_attribute_filter: Option = None; if let (Some(dataset_id), Some(filter)) = (dataset, label_filter) { From b3fdf2f6fde75448d4110aa1b3991014f917ef74 Mon Sep 17 00:00:00 2001 From: joe-prosser Date: Thu, 25 Jul 2024 09:53:40 +0100 Subject: [PATCH 2/2] Update cli/src/commands/get/comments.rs Co-authored-by: Tom Milligan --- cli/src/commands/get/comments.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/commands/get/comments.rs b/cli/src/commands/get/comments.rs index 073f7ce..73155ee 100644 --- a/cli/src/commands/get/comments.rs +++ b/cli/src/commands/get/comments.rs @@ -365,7 +365,7 @@ pub fn get_many(client: &Client, args: &GetManyCommentsArgs) -> Result<()> { let OutputLocations { jsonl_file, attachments_dir, - } = get_output_locations(path, include_attachment_content.is_some_and(|v| v))?; + } = 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) {