From d366151970bf5ced612d3d72a3fafebc14e91282 Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Tue, 7 Feb 2023 16:37:29 +0000 Subject: [PATCH] Support changing the output directory --- examples/headless/src/main.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/examples/headless/src/main.rs b/examples/headless/src/main.rs index d4dd7f1..2130930 100644 --- a/examples/headless/src/main.rs +++ b/examples/headless/src/main.rs @@ -1,4 +1,7 @@ -use std::num::NonZeroU32; +use std::{ + num::NonZeroU32, + path::{Path, PathBuf}, +}; use anyhow::{anyhow, bail, Context, Result}; use clap::{CommandFactory, Parser}; @@ -194,7 +197,12 @@ async fn render(mut scenes: SceneSet, index: usize, args: &Args) -> Result<()> { let mut writer = encoder.write_header()?; writer.write_image_data(&data)?; writer.finish()?; - std::fs::write("./test.png", result)?; + let out_path = args + .out_directory + .join(&example_scene.config.name) + .with_extension("png"); + std::fs::write(&out_path, result)?; + println!("Wrote result to {out_path:?}"); Ok(()) } @@ -212,9 +220,16 @@ struct Args { #[arg(long, short, global(false))] /// The time in seconds since the frame start, for animated scenes time: Option, + /// Directory to store the result into + #[arg(long, default_value_os_t = default_directory())] + pub out_directory: PathBuf, #[arg(long, short, global(false))] /// Display a list of all scene names print_scenes: bool, #[command(flatten)] args: scenes::Arguments, } + +fn default_directory() -> PathBuf { + Path::new(env!("CARGO_MANIFEST_DIR")).join("outputs") +}