-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.rs
79 lines (69 loc) · 2.27 KB
/
main.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// MIT/Apache2 License
mod runner;
use std::path::Path;
use std::process::exit;
use color_eyre::{eyre::bail, Result};
use owo_colors::OwoColorize;
fn main() {
// Setup error hooks.
tracing_subscriber::fmt::try_init().ok();
color_eyre::install().ok();
// Get CLI matches.
let matches = cli().get_matches();
// Run the main function.
if let Err(e) = async_io::block_on(entry(matches)) {
println!("{}{:?}", "encountered a fatal error: ".red().bold(), e);
exit(1);
}
}
async fn entry(matches: clap::ArgMatches) -> Result<()> {
match matches.subcommand() {
None => bail!("expected a subcommand"),
Some(("style", matches)) => {
let crates = read_config(matches.get_one::<String>("config").unwrap()).await?;
runner::Test::Style.run(crates).await?;
}
Some(("functionality", matches)) => {
let crates = read_config(matches.get_one::<String>("config").unwrap()).await?;
runner::Test::Functionality.run(crates).await?;
}
Some(("full", matches)) => {
let crates = read_config(matches.get_one::<String>("config").unwrap()).await?;
runner::Test::Host.run(crates).await?;
}
Some((subcommand, _matches)) => bail!("unknown subcommand {subcommand}"),
}
Ok(())
}
async fn read_config(path: impl AsRef<Path>) -> Result<Vec<runner::Crate>> {
let data = async_fs::read(path).await?;
let crates = serde_json::from_slice(&data)?;
Ok(crates)
}
fn cli() -> clap::Command {
clap::Command::new("winit-test-runner")
.subcommand(
clap::Command::new("style").arg(
clap::Arg::new("config")
.required(true)
.short('c')
.long("config"),
),
)
.subcommand(
clap::Command::new("functionality").arg(
clap::Arg::new("config")
.required(true)
.short('c')
.long("config"),
),
)
.subcommand(
clap::Command::new("full").arg(
clap::Arg::new("config")
.required(true)
.short('c')
.long("config"),
),
)
}