summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Orbekk <kj@orbekk.com>2023-07-08 16:27:25 -0400
committerKjetil Orbekk <kj@orbekk.com>2023-07-08 16:29:46 -0400
commit38a00ffd05e1106a5e8d7b6ac53b9c1519bc0296 (patch)
treed9fde03902b8aa3b37ecaf1874a4d7031825efe2
parent0a8bf0cbb82f16bce7b05e74dc1b85ca16dc15a5 (diff)
add support for output path
l---------.direnv/flake-profile2
-rw-r--r--Cargo.lock163
-rw-r--r--Cargo.toml3
-rw-r--r--flake.nix12
-rw-r--r--rust-toolchain2
-rw-r--r--src/main.rs25
6 files changed, 190 insertions, 17 deletions
diff --git a/.direnv/flake-profile b/.direnv/flake-profile
index 519b17b..8e18f4d 120000
--- a/.direnv/flake-profile
+++ b/.direnv/flake-profile
@@ -1 +1 @@
-flake-profile-3-link \ No newline at end of file
+flake-profile-7-link \ No newline at end of file
diff --git a/Cargo.lock b/Cargo.lock
index ce1491e..a9efa7e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -27,6 +27,55 @@ dependencies = [
]
[[package]]
+name = "anstream"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163"
+dependencies = [
+ "anstyle",
+ "anstyle-parse",
+ "anstyle-query",
+ "anstyle-wincon",
+ "colorchoice",
+ "is-terminal",
+ "utf8parse",
+]
+
+[[package]]
+name = "anstyle"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3a30da5c5f2d5e72842e00bcb57657162cdabef0931f40e2deb9b4140440cecd"
+
+[[package]]
+name = "anstyle-parse"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333"
+dependencies = [
+ "utf8parse",
+]
+
+[[package]]
+name = "anstyle-query"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b"
+dependencies = [
+ "windows-sys",
+]
+
+[[package]]
+name = "anstyle-wincon"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188"
+dependencies = [
+ "anstyle",
+ "windows-sys",
+]
+
+[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -71,6 +120,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
+name = "bitflags"
+version = "2.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42"
+
+[[package]]
name = "bytes"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -89,6 +144,53 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
+name = "clap"
+version = "4.3.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1640e5cc7fb47dbb8338fd471b105e7ed6c3cb2aeb00c2e067127ffd3764a05d"
+dependencies = [
+ "clap_builder",
+ "clap_derive",
+ "once_cell",
+]
+
+[[package]]
+name = "clap_builder"
+version = "4.3.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "98c59138d527eeaf9b53f35a77fcc1fad9d883116070c63d5de1c7dc7b00c72b"
+dependencies = [
+ "anstream",
+ "anstyle",
+ "clap_lex",
+ "strsim",
+]
+
+[[package]]
+name = "clap_derive"
+version = "4.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b8cd2b2a819ad6eec39e8f1d6b53001af1e5469f8c177579cdaeb313115b825f"
+dependencies = [
+ "heck",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "clap_lex"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b"
+
+[[package]]
+name = "colorchoice"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
+
+[[package]]
name = "cookie"
version = "0.16.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -263,6 +365,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e"
[[package]]
+name = "heck"
+version = "0.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
+
+[[package]]
name = "hermit-abi"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -387,6 +495,17 @@ dependencies = [
]
[[package]]
+name = "is-terminal"
+version = "0.4.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b"
+dependencies = [
+ "hermit-abi 0.3.2",
+ "rustix 0.38.3",
+ "windows-sys",
+]
+
+[[package]]
name = "itoa"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -411,6 +530,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519"
[[package]]
+name = "linux-raw-sys"
+version = "0.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "09fc20d2ca12cb9f044c93e3bd6d32d523e6e2ec3db4f7b2939cd99026ecd3f0"
+
+[[package]]
name = "lock_api"
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -462,6 +587,7 @@ dependencies = [
name = "my-dashboard"
version = "0.1.0"
dependencies = [
+ "clap",
"fantoccini",
"log",
"pretty_env_logger",
@@ -517,7 +643,7 @@ version = "0.10.55"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "345df152bc43501c5eb9e4654ff05f794effb78d4efe3d53abc158baddc0703d"
dependencies = [
- "bitflags",
+ "bitflags 1.3.2",
"cfg-if",
"foreign-types",
"libc",
@@ -642,7 +768,7 @@ version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29"
dependencies = [
- "bitflags",
+ "bitflags 1.3.2",
]
[[package]]
@@ -686,11 +812,24 @@ version = "0.37.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d69718bf81c6127a49dc64e44a742e8bb9213c0ff8869a22c308f84c1d4ab06"
dependencies = [
- "bitflags",
+ "bitflags 1.3.2",
"errno",
"io-lifetimes",
"libc",
- "linux-raw-sys",
+ "linux-raw-sys 0.3.8",
+ "windows-sys",
+]
+
+[[package]]
+name = "rustix"
+version = "0.38.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ac5ffa1efe7548069688cd7028f32591853cd7b5b756d41bcffd2353e4fc75b4"
+dependencies = [
+ "bitflags 2.3.3",
+ "errno",
+ "libc",
+ "linux-raw-sys 0.4.3",
"windows-sys",
]
@@ -721,7 +860,7 @@ version = "2.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fc758eb7bffce5b308734e9b0c1468893cae9ff70ebf13e7090be8dcbcc83a8"
dependencies = [
- "bitflags",
+ "bitflags 1.3.2",
"core-foundation",
"core-foundation-sys",
"libc",
@@ -804,6 +943,12 @@ dependencies = [
]
[[package]]
+name = "strsim"
+version = "0.10.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
+
+[[package]]
name = "syn"
version = "2.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -824,7 +969,7 @@ dependencies = [
"cfg-if",
"fastrand",
"redox_syscall",
- "rustix",
+ "rustix 0.37.23",
"windows-sys",
]
@@ -991,6 +1136,12 @@ dependencies = [
]
[[package]]
+name = "utf8parse"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
+
+[[package]]
name = "vcpkg"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 42e6f09..54cff9c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,4 +7,5 @@ edition = "2021"
fantoccini = "0.19.3"
tokio = { version = "1", features = ["full"] }
log = "0.4"
-pretty_env_logger = "0.4" \ No newline at end of file
+pretty_env_logger = "0.4"
+clap = { version = "4.3.11", features = ["derive"] }
diff --git a/flake.nix b/flake.nix
index acd46fe..c29f113 100644
--- a/flake.nix
+++ b/flake.nix
@@ -28,6 +28,7 @@
let
pkgs = import nixpkgs {
inherit system;
+ overlays = [ fenix.overlays.default];
};
inherit (pkgs) lib;
@@ -132,9 +133,14 @@
# Extra inputs can be added here
nativeBuildInputs = with pkgs; [
- cargo
- rustc
- rust-analyzer
+ (pkgs.fenix.complete.withComponents [
+ "cargo"
+ "clippy"
+ "rust-src"
+ "rustc"
+ "rustfmt"
+ ])
+ rust-analyzer-nightly
firefox
geckodriver
pkg-config
diff --git a/rust-toolchain b/rust-toolchain
index 870bbe4..07ade69 100644
--- a/rust-toolchain
+++ b/rust-toolchain
@@ -1 +1 @@
-stable \ No newline at end of file
+nightly \ No newline at end of file
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(())
}