-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
59 lines (47 loc) · 1.18 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
#![allow(dead_code)]
mod commands;
use std::panic;
use clap::{Args, Parser, Subcommand};
use euler::{Result, SILENT_PANIC};
#[derive(Parser)]
#[clap(about, author, version)]
struct Value {
#[clap(subcommand)]
command: Commands,
}
#[derive(Args)]
struct NewArgs {
problem: Option<u8>,
}
#[derive(Args)]
struct RunArgs {
problem: Option<u8>,
#[arg(short, long, default_value_t = false)]
benchmark: bool,
}
#[derive(Subcommand)]
enum Commands {
/// Handles the initialisation of a new Project Euler Problem
#[clap(alias = "n")]
New(NewArgs),
/// Runs the solution to a problem
#[clap(alias = "r")]
Run(RunArgs),
}
#[tokio::main]
pub async fn main() -> Result<()> {
panic::set_hook(Box::new(move |panic_info| {
if unsafe { SILENT_PANIC } {
std::process::exit(0);
} else {
println!("{}", panic_info.to_string());
}
}));
let value = Value::parse();
match value.command {
Commands::New(NewArgs { problem }) => commands::new::execute(problem).await,
Commands::Run(RunArgs { problem, benchmark }) => {
commands::run::execute(problem, benchmark).await
}
}
}