suggestion_demo/
suggestion_demo.rs1use flag_rs::CommandBuilder;
3
4fn main() {
5 let app = CommandBuilder::new("suggestion-demo")
6 .short("Demonstrates command suggestions")
7 .subcommand(
8 CommandBuilder::new("start")
9 .short("Start the service")
10 .run(|_| {
11 println!("Starting service...");
12 Ok(())
13 })
14 .build(),
15 )
16 .subcommand(
17 CommandBuilder::new("stop")
18 .short("Stop the service")
19 .run(|_| {
20 println!("Stopping service...");
21 Ok(())
22 })
23 .build(),
24 )
25 .subcommand(
26 CommandBuilder::new("restart")
27 .short("Restart the service")
28 .run(|_| {
29 println!("Restarting service...");
30 Ok(())
31 })
32 .build(),
33 )
34 .subcommand(
35 CommandBuilder::new("status")
36 .short("Show service status")
37 .run(|_| {
38 println!("Service is running");
39 Ok(())
40 })
41 .build(),
42 )
43 .subcommand(
44 CommandBuilder::new("config")
45 .short("Manage configuration")
46 .subcommand(
47 CommandBuilder::new("get")
48 .short("Get configuration value")
49 .run(|_| {
50 println!("Configuration value: enabled");
51 Ok(())
52 })
53 .build(),
54 )
55 .subcommand(
56 CommandBuilder::new("set")
57 .short("Set configuration value")
58 .run(|_| {
59 println!("Configuration updated");
60 Ok(())
61 })
62 .build(),
63 )
64 .build(),
65 )
66 .build();
67
68 let args: Vec<String> = std::env::args().skip(1).collect();
69
70 if !args.is_empty() {
72 println!("Command attempted: {}\n", args[0]);
73 }
74
75 if let Err(e) = app.execute(args) {
76 eprintln!("Error: {}", e);
77 std::process::exit(1);
78 }
79}