Debian Codegraph @

src/aot/generator/utils.rs

raw symbols SCIP
1 //! Helpers for writing generators
2
3 use claprust-analyzer cargo clap 4.6.6 crate/::{Argrust-analyzer cargo clap_builder 4.6.6 builder/arg/Arg#, Commandrust-analyzer cargo clap_builder 4.6.6 builder/command/Command#};
4
5 /// Gets all subcommands including child subcommands in the form of `("name", "bin_name")`.
6 ///
7 /// Subcommand `rustup toolchain install` would be converted to
8 /// `("install", "rustup toolchain install")`.
9 pub fn all_subcommandsrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/all_subcommands().(cmd: &Commandrust-analyzer cargo clap_builder 4.6.6 builder/command/Command#) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#)> {
10 let mut subcmds: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = subcommandsrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/subcommands().(cmd);
11
12 for sc_v in cmd.get_subcommandsrust-analyzer cargo clap_builder 4.6.6 builder/command/impl#[Command]get_subcommands().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(all_subcommandsrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/all_subcommands().) {
13 subcmds.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(sc_v);
14 }
15
16 subcmds
17 }
18
19 /// Finds the subcommand [`clap::Command`] from the given [`clap::Command`] with the given path.
20 ///
21 /// <div class="warning">
22 ///
23 /// **NOTE:** `path` should not contain the root `bin_name`.
24 ///
25 /// </div>
26 pub fn find_subcommand_with_pathrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/find_subcommand_with_path().<'cmd>(p: &'cmd Commandrust-analyzer cargo clap_builder 4.6.6 builder/command/Command#, path: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&str>) -> &'cmd Commandrust-analyzer cargo clap_builder 4.6.6 builder/command/Command# {
27 let mut cmd = p;
28
29 for sc in path {
30 cmd = cmd.find_subcommandrust-analyzer cargo clap_builder 4.6.6 builder/command/impl#[Command]find_subcommand().(sc).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
31 }
32
33 cmd
34 }
35
36 /// Gets subcommands of [`clap::Command`] in the form of `("name", "bin_name")`.
37 ///
38 /// Subcommand `rustup toolchain install` would be converted to
39 /// `("install", "rustup toolchain install")`.
40 pub fn subcommandsrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/subcommands().(p: &Commandrust-analyzer cargo clap_builder 4.6.6 builder/command/Command#) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#)> {
41 debugrust-analyzer cargo clap_complete 4.6.8 macros/debug!!("subcommands: name={}", p.get_name());
42 debugrust-analyzer cargo clap_complete 4.6.8 macros/debug!!("subcommands: Has subcommands...{:?}", p.has_subcommands());
43
44 let mut subcmds = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![];
45
46 for sc in p.get_subcommandsrust-analyzer cargo clap_builder 4.6.6 builder/command/impl#[Command]get_subcommands().() {
47 let sc_bin_name = sc.get_bin_namerust-analyzer cargo clap_builder 4.6.6 builder/command/impl#[Command]get_bin_name().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
48
49 debugrust-analyzer cargo clap_complete 4.6.8 macros/debug!!(
50 "subcommands:iter: name={}, bin_name={}",
51 sc.get_name(),
52 sc_bin_name
53 );
54 subcmds.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().((sc.get_namerust-analyzer cargo clap_builder 4.6.6 builder/command/impl#[Command]get_name().().to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), sc_bin_name.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()));
55
56 for alias in sc.get_visible_aliasesrust-analyzer cargo clap_builder 4.6.6 builder/command/impl#[Command]get_visible_aliases().() {
57 debugrust-analyzer cargo clap_complete 4.6.8 macros/debug!!(
58 "subcommands:iter: alias={}, bin_name={}",
59 alias, sc_bin_name
60 );
61 subcmds.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().((alias.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), sc_bin_name.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()));
62 }
63 }
64
65 subcmds
66 }
67
68 /// Gets all the short options, their visible aliases and flags of a [`clap::Command`].
69 /// Includes `h` and `V` depending on the [`clap::Command`] settings.
70 pub fn shorts_and_visible_aliasesrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/shorts_and_visible_aliases().(p: &Commandrust-analyzer cargo clap_builder 4.6.6 builder/command/Command#) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<char> {
71 debugrust-analyzer cargo clap_complete 4.6.8 macros/debug!!("shorts: name={}", p.get_name());
72
73 p.get_argumentsrust-analyzer cargo clap_builder 4.6.6 builder/command/impl#[Command]get_arguments().()
74 .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|a| {
75 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().a.is_positionalrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]is_positional().() {
76 if a.get_visible_short_aliasesrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]get_visible_short_aliases().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() && a.get_shortrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]get_short().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
77 let mut shorts_and_visible_aliases = a.get_visible_short_aliasesrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]get_visible_short_aliases().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
78 shorts_and_visible_aliases.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(a.get_shortrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]get_short().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().());
79 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(shorts_and_visible_aliases)
80 } else if a.get_visible_short_aliasesrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]get_visible_short_aliases().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() && a.get_shortrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]get_short().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
81 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![a.get_shortrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]get_short().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()])
82 } else {
83 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
84 }
85 } else {
86 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
87 }
88 })
89 .flattenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flatten().()
90 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()
91 }
92
93 /// Gets all the long options, their visible aliases and flags of a [`clap::Command`].
94 /// Includes `help` and `version` depending on the [`clap::Command`] settings.
95 pub fn longs_and_visible_aliasesrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/longs_and_visible_aliases().(p: &Commandrust-analyzer cargo clap_builder 4.6.6 builder/command/Command#) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
96 debugrust-analyzer cargo clap_complete 4.6.8 macros/debug!!("longs: name={}", p.get_name());
97
98 p.get_argumentsrust-analyzer cargo clap_builder 4.6.6 builder/command/impl#[Command]get_arguments().()
99 .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|a| {
100 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().a.is_positionalrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]is_positional().() {
101 if a.get_visible_aliasesrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]get_visible_aliases().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() && a.get_longrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]get_long().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
102 let mut visible_aliases: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = a
103 .get_visible_aliasesrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]get_visible_aliases().()
104 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()
105 .into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().()
106 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|s| s.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().())
107 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
108 visible_aliases.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(a.get_longrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]get_long().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().());
109 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(visible_aliases)
110 } else if a.get_visible_aliasesrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]get_visible_aliases().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() && a.get_longrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]get_long().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
111 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![a.get_longrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]get_long().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()])
112 } else {
113 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
114 }
115 } else {
116 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
117 }
118 })
119 .flattenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flatten().()
120 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()
121 }
122
123 /// Gets all the flags of a [`clap::Command`].
124 /// Includes `help` and `version` depending on the [`clap::Command`] settings.
125 pub fn flagsrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/flags().(p: &Commandrust-analyzer cargo clap_builder 4.6.6 builder/command/Command#) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Argrust-analyzer cargo clap_builder 4.6.6 builder/arg/Arg#> {
126 debugrust-analyzer cargo clap_complete 4.6.8 macros/debug!!("flags: name={}", p.get_name());
127 p.get_argumentsrust-analyzer cargo clap_builder 4.6.6 builder/command/impl#[Command]get_arguments().()
128 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|a| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().a.get_num_argsrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]get_num_args().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("built").takes_valuesrust-analyzer cargo clap_builder 4.6.6 builder/range/impl#[ValueRange]takes_values().() && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().a.is_positionalrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]is_positional().())
129 .clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().()
130 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()
131 }
132
133 /// Get the possible values for completion
134 pub fn possible_valuesrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/possible_values().(a: &Argrust-analyzer cargo clap_builder 4.6.6 builder/arg/Arg#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<claprust-analyzer cargo clap 4.6.6 crate/::builderrust-analyzer cargo clap_builder 4.6.6 builder/::PossibleValuerust-analyzer cargo clap_builder 4.6.6 builder/possible_value/PossibleValue#>> {
135 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().a.get_num_argsrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]get_num_args().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("built").takes_valuesrust-analyzer cargo clap_builder 4.6.6 builder/range/impl#[ValueRange]takes_values().() {
136 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
137 } else {
138 a.get_value_parserrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]get_value_parser().()
139 .possible_valuesrust-analyzer cargo clap_builder 4.6.6 builder/value_parser/impl#[ValueParser]possible_values().()
140 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|pvs| pvs.collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().())
141 }
142 }
143
144 #[cfg(test)]
145 mod testsrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/tests/ {
146 use superrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/::*;
147 use claprust-analyzer cargo clap 4.6.6 crate/::Argrust-analyzer cargo clap_builder 4.6.6 builder/arg/Arg#;
148 use claprust-analyzer cargo clap 4.6.6 crate/::ArgActionrust-analyzer cargo clap_builder 4.6.6 builder/action/ArgAction#;
149
150 fn common_apprust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/tests/common_app().() -> Commandrust-analyzer cargo clap_builder 4.6.6 builder/command/Command# {
151 Commandrust-analyzer cargo clap_builder 4.6.6 builder/command/Command#::newrust-analyzer cargo clap_builder 4.6.6 builder/command/impl#[Command]new().("myapp")
152 .subcommandrust-analyzer cargo clap_builder 4.6.6 builder/command/impl#[Command]subcommand().(
153 Commandrust-analyzer cargo clap_builder 4.6.6 builder/command/Command#::newrust-analyzer cargo clap_builder 4.6.6 builder/command/impl#[Command]new().("test").subcommandrust-analyzer cargo clap_builder 4.6.6 builder/command/impl#[Command]subcommand().(Commandrust-analyzer cargo clap_builder 4.6.6 builder/command/Command#::newrust-analyzer cargo clap_builder 4.6.6 builder/command/impl#[Command]new().("config")).argrust-analyzer cargo clap_builder 4.6.6 builder/command/impl#[Command]arg().(
154 Argrust-analyzer cargo clap_builder 4.6.6 builder/arg/Arg#::newrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]new().("file")
155 .shortrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]short().('f')
156 .short_aliasrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]short_alias().('c')
157 .visible_short_aliasrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]visible_short_alias().('p')
158 .longrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]long().("file")
159 .actionrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]action().(ArgActionrust-analyzer cargo clap_builder 4.6.6 builder/action/ArgAction#::SetTruerust-analyzer cargo clap_builder 4.6.6 builder/action/ArgAction#SetTrue#)
160 .visible_aliasrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]visible_alias().("path"),
161 ),
162 )
163 .subcommandrust-analyzer cargo clap_builder 4.6.6 builder/command/impl#[Command]subcommand().(Commandrust-analyzer cargo clap_builder 4.6.6 builder/command/Command#::newrust-analyzer cargo clap_builder 4.6.6 builder/command/impl#[Command]new().("hello"))
164 .bin_namerust-analyzer cargo clap_builder 4.6.6 builder/command/impl#[Command]bin_name().("my-cmd")
165 }
166
167 fn builtrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/tests/built().() -> Commandrust-analyzer cargo clap_builder 4.6.6 builder/command/Command# {
168 let mut cmd = common_apprust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/tests/common_app().();
169
170 cmd.buildrust-analyzer cargo clap_builder 4.6.6 builder/command/impl#[Command]build().();
171 cmd
172 }
173
174 fn built_with_versionrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/tests/built_with_version().() -> Commandrust-analyzer cargo clap_builder 4.6.6 builder/command/Command# {
175 let mut cmd = common_apprust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/tests/common_app().().versionrust-analyzer cargo clap_builder 4.6.6 builder/command/impl#[Command]version().("3.0");
176
177 cmd.buildrust-analyzer cargo clap_builder 4.6.6 builder/command/impl#[Command]build().();
178 cmd
179 }
180
181 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
182 fn test_subcommandsrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/tests/test_subcommands().() {
183 let cmd = built_with_versionrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/tests/built_with_version().();
184
185 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
186 subcommandsrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/subcommands().(&cmd),
187 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
188 ("test".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), "my-cmd test".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()),
189 ("hello".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), "my-cmd hello".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()),
190 ("help".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), "my-cmd help".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()),
191 ]
192 );
193 }
194
195 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
196 fn test_all_subcommandsrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/tests/test_all_subcommands().() {
197 let cmd = built_with_versionrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/tests/built_with_version().();
198
199 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
200 all_subcommandsrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/all_subcommands().(&cmd),
201 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
202 ("test".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), "my-cmd test".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()),
203 ("hello".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), "my-cmd hello".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()),
204 ("help".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), "my-cmd help".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()),
205 ("config".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), "my-cmd test config".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()),
206 ("help".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), "my-cmd test help".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()),
207 ("config".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), "my-cmd test help config".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()),
208 ("help".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), "my-cmd test help help".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()),
209 ("test".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), "my-cmd help test".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()),
210 ("hello".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), "my-cmd help hello".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()),
211 ("help".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), "my-cmd help help".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()),
212 ("config".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), "my-cmd help test config".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()),
213 ]
214 );
215 }
216
217 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
218 fn test_find_subcommand_with_pathrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/tests/test_find_subcommand_with_path().() {
219 let cmd = built_with_versionrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/tests/built_with_version().();
220 let sc_app = find_subcommand_with_pathrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/find_subcommand_with_path().(&cmd, "test config".splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(' ').collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().());
221
222 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sc_app.get_namerust-analyzer cargo clap_builder 4.6.6 builder/command/impl#[Command]get_name().(), "config");
223 }
224
225 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
226 fn test_flagsrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/tests/test_flags().() {
227 let cmd = built_with_versionrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/tests/built_with_version().();
228 let actual_flags = flagsrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/flags().(&cmd);
229
230 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(actual_flags.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2);
231 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(actual_flags[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..get_longrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]get_long().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("help"));
232 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(actual_flags[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..get_longrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]get_long().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("version"));
233
234 let sc_flags = flagsrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/flags().(find_subcommand_with_pathrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/find_subcommand_with_path().(&cmd, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["test"]));
235
236 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sc_flags.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2);
237 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sc_flags[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..get_longrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]get_long().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("file"));
238 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sc_flags[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..get_longrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]get_long().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("help"));
239 }
240
241 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
242 fn test_flag_subcommandrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/tests/test_flag_subcommand().() {
243 let cmd = builtrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/tests/built().();
244 let actual_flags = flagsrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/flags().(&cmd);
245
246 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(actual_flags.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1);
247 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(actual_flags[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..get_longrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]get_long().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("help"));
248
249 let sc_flags = flagsrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/flags().(find_subcommand_with_pathrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/find_subcommand_with_path().(&cmd, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["test"]));
250
251 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sc_flags.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2);
252 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sc_flags[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..get_longrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]get_long().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("file"));
253 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sc_flags[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..get_longrust-analyzer cargo clap_builder 4.6.6 builder/arg/impl#[Arg]get_long().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("help"));
254 }
255
256 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
257 fn test_shortsrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/tests/test_shorts().() {
258 let cmd = built_with_versionrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/tests/built_with_version().();
259 let shorts = shorts_and_visible_aliasesrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/shorts_and_visible_aliases().(&cmd);
260
261 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(shorts.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2);
262 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(shorts[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., 'h');
263 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(shorts[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., 'V');
264
265 let sc_shorts = shorts_and_visible_aliasesrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/shorts_and_visible_aliases().(find_subcommand_with_pathrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/find_subcommand_with_path().(&cmd, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["test"]));
266
267 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sc_shorts.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 3);
268 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sc_shorts[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., 'p');
269 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sc_shorts[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., 'f');
270 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sc_shorts[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., 'h');
271 }
272
273 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
274 fn test_longsrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/tests/test_longs().() {
275 let cmd = built_with_versionrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/tests/built_with_version().();
276 let longs = longs_and_visible_aliasesrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/longs_and_visible_aliases().(&cmd);
277
278 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(longs.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2);
279 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(longs[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., "help");
280 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(longs[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., "version");
281
282 let sc_longs = longs_and_visible_aliasesrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/longs_and_visible_aliases().(find_subcommand_with_pathrust-analyzer cargo clap_complete 4.6.8 aot/generator/utils/find_subcommand_with_path().(&cmd, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["test"]));
283
284 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sc_longs.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 3);
285 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sc_longs[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., "path");
286 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sc_longs[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., "file");
287 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sc_longs[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., "help");
288 }
289 }