1 use clap
::builder
::PossibleValue
;
2 #[cfg(feature = "unstable-dynamic")]
3 use clap
::{FromArgMatches, Subcommand}
;
4 use clap_complete
::{generate, Generator, Shell}
;
7 let matches
= cli().get_matches();
8 if let Some(generator
) = matches
.get_one
::<Shell
>("generate") {
10 eprintln
!("Generating completion file for {generator}...");
11 print_completions(*generator
, &mut cmd
);
15 #[cfg(feature = "unstable-dynamic")]
16 if let Ok(completions
) =
17 clap_complete
::dynamic
::shells
::CompleteCommand
::from_arg_matches(&matches
)
19 completions
.complete(&mut cli());
23 println
!("{:?}", matches
);
26 fn print_completions
<G
: Generator
>(gen
: G
, cmd
: &mut clap
::Command
) {
27 generate(gen
, cmd
, cmd
.get_name().to_string(), &mut std
::io
::stdout());
30 #[allow(clippy::let_and_return)]
31 fn cli() -> clap
::Command
{
32 let cli
= clap
::Command
::new("exhaustive")
34 .propagate_version(true)
36 clap
::Arg
::new("global")
39 .action(clap
::ArgAction
::SetTrue
)
41 clap
::Arg
::new("generate")
44 .value_parser(clap
::value_parser
!(Shell
))
48 clap
::Command
::new("action").args([
49 clap
::Arg
::new("set-true")
51 .action(clap
::ArgAction
::SetTrue
)
55 .action(clap
::ArgAction
::Set
)
57 clap
::Arg
::new("count")
59 .action(clap
::ArgAction
::Count
)
61 clap
::Arg
::new("choice")
63 .value_parser(["first", "second"])
66 clap
::Command
::new("quote")
68 clap
::Arg
::new("single-quotes")
69 .long("single-quotes")
70 .action(clap
::ArgAction
::SetTrue
)
71 .help("Can be 'always', 'auto', or 'never'"),
72 clap
::Arg
::new("double-quotes")
73 .long("double-quotes")
74 .action(clap
::ArgAction
::SetTrue
)
75 .help("Can be \"always\", \"auto\", or \"never\""),
76 clap
::Arg
::new("backticks")
78 .action(clap
::ArgAction
::SetTrue
)
79 .help("For more information see `echo test`"),
80 clap
::Arg
::new("backslash")
82 .action(clap
::ArgAction
::SetTrue
)
84 clap
::Arg
::new("brackets")
86 .action(clap
::ArgAction
::SetTrue
)
87 .help("List packages [filter]"),
88 clap
::Arg
::new("expansions")
90 .action(clap
::ArgAction
::SetTrue
)
91 .help("Execute the shell command with $SHELL"),
92 clap
::Arg
::new("choice")
94 .action(clap
::ArgAction
::Set
)
95 .value_parser(clap
::builder
::PossibleValuesParser
::new([
96 PossibleValue
::new("bash").help("bash (shell)"),
97 PossibleValue
::new("fish").help("fish shell"),
98 PossibleValue
::new("zsh").help("zsh shell"),
102 clap
::Command
::new("cmd-single-quotes")
103 .about("Can be 'always', 'auto', or 'never'"),
104 clap
::Command
::new("cmd-double-quotes")
105 .about("Can be \"always\", \"auto\", or \"never\""),
106 clap
::Command
::new("cmd-backticks")
107 .about("For more information see `echo test`"),
108 clap
::Command
::new("cmd-backslash").about("Avoid '\\n'"),
109 clap
::Command
::new("cmd-brackets").about("List packages [filter]"),
110 clap
::Command
::new("cmd-expansions")
111 .about("Execute the shell command with $SHELL"),
112 clap
::Command
::new("escape-help").about("\\tab\t\"'\nNew Line"),
114 clap
::Command
::new("value").args([
115 clap
::Arg
::new("delim").long("delim").value_delimiter('
,'
),
116 clap
::Arg
::new("tuple").long("tuple").num_args(2),
117 clap
::Arg
::new("require-eq")
119 .require_equals(true),
120 clap
::Arg
::new("term").num_args(1..).value_terminator(";"),
122 clap
::Command
::new("pacman").subcommands([
123 clap
::Command
::new("one").long_flag("one").short_flag('o'
),
124 clap
::Command
::new("two").long_flag("two").short_flag('t'
),
126 clap
::Command
::new("last")
127 .args([clap
::Arg
::new("first"), clap
::Arg
::new("free").last(true)]),
128 clap
::Command
::new("alias").args([
129 clap
::Arg
::new("flag")
131 .visible_short_alias('F'
)
133 .action(clap
::ArgAction
::SetTrue
)
134 .visible_alias("flg")
136 clap
::Arg
::new("option")
138 .visible_short_alias('O'
)
140 .visible_alias("opt")
142 .action(clap
::ArgAction
::Set
),
143 clap
::Arg
::new("positional"),
145 clap
::Command
::new("hint").args([
146 clap
::Arg
::new("choice")
148 .action(clap
::ArgAction
::Set
)
149 .value_parser(["bash", "fish", "zsh"]),
150 clap
::Arg
::new("unknown")
152 .value_hint(clap
::ValueHint
::Unknown
),
153 clap
::Arg
::new("other")
155 .value_hint(clap
::ValueHint
::Other
),
156 clap
::Arg
::new("path")
159 .value_hint(clap
::ValueHint
::AnyPath
),
160 clap
::Arg
::new("file")
163 .value_hint(clap
::ValueHint
::FilePath
),
164 clap
::Arg
::new("dir")
167 .value_hint(clap
::ValueHint
::DirPath
),
168 clap
::Arg
::new("exe")
171 .value_hint(clap
::ValueHint
::ExecutablePath
),
172 clap
::Arg
::new("cmd_name")
174 .value_hint(clap
::ValueHint
::CommandName
),
175 clap
::Arg
::new("cmd")
178 .value_hint(clap
::ValueHint
::CommandString
),
179 clap
::Arg
::new("command_with_args")
180 .action(clap
::ArgAction
::Set
)
182 .trailing_var_arg(true)
183 .value_hint(clap
::ValueHint
::CommandWithArguments
),
184 clap
::Arg
::new("user")
187 .value_hint(clap
::ValueHint
::Username
),
188 clap
::Arg
::new("host")
191 .value_hint(clap
::ValueHint
::Hostname
),
192 clap
::Arg
::new("url")
194 .value_hint(clap
::ValueHint
::Url
),
195 clap
::Arg
::new("email")
197 .value_hint(clap
::ValueHint
::EmailAddress
),
200 #[cfg(feature = "unstable-dynamic")]
201 let cli
= clap_complete
::dynamic
::shells
::CompleteCommand
::augment_subcommands(cli
);