-
Notifications
You must be signed in to change notification settings - Fork 2
/
ethshadow.rs
52 lines (45 loc) · 1.8 KB
/
ethshadow.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env rust-script
//! ```cargo
//! [dependencies]
//! ethshadow = { path="lib" }
//! clap = { version = "4.5", features = ["cargo"] }
//! ```
use clap::{arg, command, value_parser};
use color_eyre::eyre::WrapErr;
use color_eyre::Result;
use env_logger::Env;
use ethshadow::generate;
use std::env;
use std::fs::File;
use std::os::unix::prelude::CommandExt;
use std::path::PathBuf;
fn main() -> Result<()> {
let matches = command!() // requires `cargo` feature
.bin_name("ethshadow")
.arg(arg!(dir: -d [DIR] "Output directory for ethshadow and Shadow")
.value_parser(value_parser!(PathBuf))
.default_value("data"))
.arg(arg!(genonly: --"gen-only" "Generate data dir only, do not invoke Shadow"))
.arg(arg!(config: <CONFIG> "Configuration file. See CONFIG.md")
.value_parser(value_parser!(PathBuf)))
.arg(arg!(shadow_cli: [SHADOW_CLI_OPTION]... "Optional options passed on to Shadow, except \"-d\" and the config")
.last(true))
.get_matches();
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
let dir = matches
.get_one::<PathBuf>("dir")
.expect("there is a default in place");
let config = matches.get_one::<PathBuf>("config").expect("required arg");
let config = File::open(config).wrap_err("Unable to read the config")?;
let mut invocation =
generate(config, dir, false).wrap_err("Failed to generate data directory")?;
if !matches.get_flag("genonly") {
if let Some(user_args) = matches.get_many::<String>("shadow_cli") {
invocation.with_user_args(user_args);
}
// if exec() returns, the call failed!
Err(invocation.command().exec()).wrap_err("Failed to invoke Shadow")
} else {
Ok(())
}
}