1use clap::Parser;
2use clap_tui::Tui;
3
4#[derive(Debug, Parser, PartialEq, Eq)]
5#[command(name = "simple", about = "Simple example", version = "0.1.0")]
6enum Command {
7 Tui,
9 Hello {
11 #[arg(short, long)]
13 verbose: bool,
14
15 #[arg(short, long, default_value = "world")]
17 name: String,
18
19 #[arg(long, default_value_t = 1)]
21 count: u32,
22 },
23}
24
25fn dispatch(command: Command) {
26 match command {
27 Command::Tui => {}
28 Command::Hello {
29 verbose,
30 name,
31 count,
32 } => {
33 if verbose {
34 println!("Verbose mode on");
35 }
36 for _ in 0..count {
37 println!("Hello, {name}!");
38 }
39 }
40 }
41}
42
43fn main() -> Result<(), clap_tui::TuiError> {
44 match Command::parse() {
45 Command::Tui => {
46 if let Some(command) = Tui::<Command>::new().hide_entrypoint("tui")?.run()? {
47 dispatch(command);
48 }
49 }
50 command => dispatch(command),
51 }
52
53 Ok(())
54}