diff options
author | Kjetil Orbekk <kj@orbekk.com> | 2023-07-08 16:27:25 -0400 |
---|---|---|
committer | Kjetil Orbekk <kj@orbekk.com> | 2023-07-08 16:29:46 -0400 |
commit | 38a00ffd05e1106a5e8d7b6ac53b9c1519bc0296 (patch) | |
tree | d9fde03902b8aa3b37ecaf1874a4d7031825efe2 /src | |
parent | 0a8bf0cbb82f16bce7b05e74dc1b85ca16dc15a5 (diff) |
add support for output path
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs index 8befc88..e0d42f9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,15 +1,27 @@ -use std::{process::Command, error::Error, fs, env, time::Duration}; +use std::{process::Command, error::Error, fs, env, time::Duration, path::Path}; use fantoccini::{ClientBuilder, Locator}; use log::info; use tokio::time; +use clap::Parser; static PROFILE_ROOT: &str = "/tmp/geckodriver-dashboard"; +/// Simple program to greet a person +#[derive(Parser, Debug)] +#[command(author, version, about, long_about = None)] +struct Args { + /// Output path for png image. + #[arg(short, long)] + path: String, +} + // let's set up the sequence of steps we want the browser to take #[tokio::main] async fn main() -> Result<(), Box<dyn Error>> { pretty_env_logger::init(); + let args = Args::parse(); + info!("Current directory: {}", env::current_dir()?.display()); fs::create_dir(PROFILE_ROOT).ok(); let mut geckodriver = Command::new("geckodriver") @@ -26,11 +38,14 @@ async fn main() -> Result<(), Box<dyn Error>> { let e = c.find(Locator::Css("#app")).await?; let img = e.screenshot().await?; - fs::write("index.png", img)?; + let output_path = Path::new(&args.path); + let tmp_path = output_path.join(".tmp"); + fs::write(&tmp_path, img)?; + fs::rename(&tmp_path, output_path)?; time::sleep(Duration::from_secs(15)).await; } - c.close().await?; - geckodriver.kill()?; - Ok(()) + // c.close().await?; + // geckodriver.kill()?; + // Ok(()) } |