Repository navigation
Expand file tree
/
Copy pathmain.rs
More file actions
62 lines (55 loc) · 1.42 KB
/
Copy pathmain.rs
File metadata and controls
62 lines (55 loc) · 1.42 KB
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
mod chifoumi;
mod greetings;
use chifoumi::{play, Game};
use greetings::greets;
use clap::{Parser, Subcommand};
use crate::chifoumi::random_game;
#[derive(Parser)]
#[clap(
author = "Julien Rollin",
version = "1.0.0",
about = "Crabby cli",
long_about = None
)]
#[clap(propagate_version = true)]
struct Cli {
#[clap(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
/// Greets with name
Greets {
/// Name of the person to greet
#[clap(short, long, value_parser)]
name: String,
},
/// chifoumi with players
Chifoumi {
#[clap(short = 'a', long, value_enum)]
one: Game,
/// random game if not provided
#[clap(short = 'b', long, value_enum)]
two: Option<Game>,
},
}
fn main() {
let cli = Cli::parse();
match &cli.command {
Commands::Chifoumi { one, two } => match two {
// player two provided
Some(p) => {
let result = play(one.clone(), p.clone());
println!("p1: {:?} vs p2: {:?} => {:?}", one, p, result)
}
None => {
let random = random_game();
let result = play(one.clone(), random.clone());
println!("p1: {:?} vs p2: {:?} => {:?}", one, random, result)
}
},
Commands::Greets { name } => {
println!("{}", greets(name));
}
}
}