Debian Codegraph @

debian/missing-sources/clap/src/bin/stdio-fixture.rs

raw
1 use clap::{builder::PossibleValue, Arg, ArgAction, Command};
2
3 fn main() {
4 #[allow(unused_mut)]
5 let mut cmd = Command::new("stdio-fixture")
6 .version("1.0")
7 .long_version("1.0 - a2132c")
8 .term_width(0)
9 .max_term_width(0)
10 .arg_required_else_help(true)
11 .subcommand(Command::new("more"))
12 .subcommand(
13 Command::new("test")
14 .visible_alias("do-stuff")
15 .long_about("Subcommand with one visible alias"),
16 )
17 .subcommand(
18 Command::new("test_2")
19 .visible_aliases(["do-other-stuff", "tests"])
20 .about("several visible aliases")
21 .long_about("Subcommand with multiple visible aliases"),
22 )
23 .subcommand(
24 Command::new("test_3")
25 .long_flag("test")
26 .about("several visible long flag aliases")
27 .visible_long_flag_aliases(["testing", "testall", "test_all"]),
28 )
29 .subcommand(
30 Command::new("test_4")
31 .short_flag('t')
32 .about("several visible short flag aliases")
33 .visible_short_flag_aliases(['q', 'w']),
34 )
35 .subcommand(
36 Command::new("test_5")
37 .short_flag('e')
38 .long_flag("test-hdr")
39 .about("all kinds of visible aliases")
40 .visible_aliases(["tests_4k"])
41 .visible_long_flag_aliases(["thetests", "t4k"])
42 .visible_short_flag_aliases(['r', 'y']),
43 )
44 .arg(
45 Arg::new("verbose")
46 .long("verbose")
47 .help("log")
48 .action(ArgAction::SetTrue)
49 .long_help("more log"),
50 )
51 .arg(
52 Arg::new("config")
53 .action(ArgAction::Set)
54 .help("Speed configuration")
55 .short('c')
56 .long("config")
57 .value_name("MODE")
58 .value_parser([
59 PossibleValue::new("fast"),
60 PossibleValue::new("slow").help("slower than fast"),
61 PossibleValue::new("secret speed").hide(true),
62 ])
63 .default_value("fast"),
64 )
65 .arg(
66 Arg::new("name")
67 .action(ArgAction::Set)
68 .help("App name")
69 .long_help("Set the instance app name")
70 .value_name("NAME")
71 .visible_alias("app-name")
72 .default_value("clap"),
73 )
74 .arg(
75 Arg::new("fruits")
76 .short('f')
77 .visible_short_alias('b')
78 .action(ArgAction::Append)
79 .value_name("FRUITS")
80 .help("List of fruits")
81 .default_values(["apple", "banane", "orange"]),
82 );
83 #[cfg(feature = "env")]
84 {
85 cmd = cmd.arg(
86 Arg::new("env_arg")
87 .help("Read from env var when arg is not present.")
88 .value_name("ENV")
89 .env("ENV_ARG"),
90 );
91 }
92 #[cfg(feature = "color")]
93 {
94 use clap::builder::styling::{AnsiColor, Styles};
95 const STYLES: Styles = Styles::styled()
96 .header(AnsiColor::Green.on_default().bold())
97 .error(AnsiColor::Red.on_default().bold())
98 .usage(AnsiColor::Green.on_default().bold().underline())
99 .literal(AnsiColor::Blue.on_default().bold())
100 .placeholder(AnsiColor::Cyan.on_default())
101 .valid(AnsiColor::Green.on_default())
102 .invalid(AnsiColor::Magenta.on_default().bold())
103 .context(AnsiColor::Yellow.on_default().dimmed())
104 .context_value(AnsiColor::Yellow.on_default().italic());
105 cmd = cmd.styles(STYLES);
106 }
107 cmd.get_matches();
108 }