Debian Codegraph @

debian/rust-vendor/clap/examples/derive_ref/interop_tests.md

raw
1 Following are tests for the interop examples in this directory.
2
3 ## Augment Args
4
5 ```console
6 $ interop_augment_args
7 Value of built: false
8 Value of derived via ArgMatches: false
9 Value of derived: DerivedArgs {
10 derived: false,
11 }
12
13 ```
14
15 ```console
16 $ interop_augment_args -b --derived
17 Value of built: true
18 Value of derived via ArgMatches: true
19 Value of derived: DerivedArgs {
20 derived: true,
21 }
22
23 ```
24
25 ```console
26 $ interop_augment_args -d --built
27 Value of built: true
28 Value of derived via ArgMatches: true
29 Value of derived: DerivedArgs {
30 derived: true,
31 }
32
33 ```
34
35 ```console
36 $ interop_augment_args --unknown
37 ? failed
38 error: unexpected argument '--unknown' found
39
40 Usage: interop_augment_args[EXE] [OPTIONS]
41
42 For more information, try '--help'.
43
44 ```
45
46 ## Augment Subcommands
47
48 ```console
49 $ interop_augment_subcommands
50 ? failed
51 error: a subcommand is required but one was not provided
52 ```
53
54 ```console
55 $ interop_augment_subcommands derived
56 Derived subcommands: Derived {
57 derived_flag: false,
58 }
59
60 ```
61
62 ```console
63 $ interop_augment_subcommands derived --derived-flag
64 Derived subcommands: Derived {
65 derived_flag: true,
66 }
67
68 ```
69
70 ```console
71 $ interop_augment_subcommands derived --unknown
72 ? failed
73 error: unexpected argument '--unknown' found
74
75 Usage: interop_augment_subcommands[EXE] derived [OPTIONS]
76
77 For more information, try '--help'.
78
79 ```
80
81 ```console
82 $ interop_augment_subcommands unknown
83 ? failed
84 error: unrecognized subcommand 'unknown'
85
86 Usage: interop_augment_subcommands[EXE] [COMMAND]
87
88 For more information, try '--help'.
89
90 ```
91
92 ## Hand-Implemented Subcommand
93
94 ```console
95 $ interop_hand_subcommand
96 ? failed
97 Usage: interop_hand_subcommand[EXE] [OPTIONS] <COMMAND>
98
99 Commands:
100 add
101 remove
102 help Print this message or the help of the given subcommand(s)
103
104 Options:
105 -t, --top-level
106 -h, --help Print help
107
108 ```
109
110 ```console
111 $ interop_hand_subcommand add
112 Cli {
113 top_level: false,
114 subcommand: Add(
115 AddArgs {
116 name: [],
117 },
118 ),
119 }
120
121 ```
122
123 ```console
124 $ interop_hand_subcommand add a b c
125 Cli {
126 top_level: false,
127 subcommand: Add(
128 AddArgs {
129 name: [
130 "a",
131 "b",
132 "c",
133 ],
134 },
135 ),
136 }
137
138 ```
139
140 ```console
141 $ interop_hand_subcommand add --unknown
142 ? failed
143 error: unexpected argument '--unknown' found
144
145 tip: to pass '--unknown' as a value, use '-- --unknown'
146
147 Usage: interop_hand_subcommand[EXE] add [NAME]...
148
149 For more information, try '--help'.
150
151 ```
152
153 ```console
154 $ interop_hand_subcommand remove
155 Cli {
156 top_level: false,
157 subcommand: Remove(
158 RemoveArgs {
159 force: false,
160 name: [],
161 },
162 ),
163 }
164
165 ```
166
167 ```console
168 $ interop_hand_subcommand remove --force a b c
169 Cli {
170 top_level: false,
171 subcommand: Remove(
172 RemoveArgs {
173 force: true,
174 name: [
175 "a",
176 "b",
177 "c",
178 ],
179 },
180 ),
181 }
182
183 ```
184
185 ```console
186 $ interop_hand_subcommand unknown
187 ? failed
188 error: unrecognized subcommand 'unknown'
189
190 Usage: interop_hand_subcommand[EXE] [OPTIONS] <COMMAND>
191
192 For more information, try '--help'.
193
194 ```
195
196 ## Flatten Hand-Implemented Args
197
198 ```console
199 $ interop_flatten_hand_args
200 Cli {
201 top_level: false,
202 more_args: CliArgs {
203 foo: false,
204 bar: false,
205 quuz: None,
206 },
207 }
208
209 ```
210
211 ```console
212 $ interop_flatten_hand_args -f --bar
213 Cli {
214 top_level: false,
215 more_args: CliArgs {
216 foo: true,
217 bar: true,
218 quuz: None,
219 },
220 }
221
222 ```
223
224 ```console
225 $ interop_flatten_hand_args --quuz abc
226 Cli {
227 top_level: false,
228 more_args: CliArgs {
229 foo: false,
230 bar: false,
231 quuz: Some(
232 "abc",
233 ),
234 },
235 }
236
237 ```
238
239 ```console
240 $ interop_flatten_hand_args --unknown
241 ? failed
242 error: unexpected argument '--unknown' found
243
244 Usage: interop_flatten_hand_args[EXE] [OPTIONS]
245
246 For more information, try '--help'.
247
248 ```