Skip to main content

perforce_cli/
global.rs

1use std::{path::PathBuf, process::Command};
2
3///
4/// ## Synopsis
5///
6/// Global options for Perforce commands; these options can be supplied on the command line before any Perforce command.
7///
8#[derive(Debug, Clone, Default)]
9pub struct GlobalOpts {
10    batch_size: Option<u32>,
11
12    client: Option<String>,
13
14    dir: Option<PathBuf>,
15
16    progress_indicators: bool,
17
18    #[cfg(not(feature = "lt2019_1"))]
19    standard_in: bool,
20
21    marshalled_formatted: bool,
22
23    #[cfg(not(feature = "lt2020_1"))]
24    json_formatted: bool,
25
26    host: Option<String>,
27
28    #[cfg(not(feature = "lt2019_1"))]
29    standard_out: bool,
30
31    port: Option<String>,
32
33    pass: Option<String>,
34
35    retries: Option<u32>,
36
37    prepend_descriptive: bool,
38
39    user: Option<String>,
40
41    argfile: Option<PathBuf>,
42
43    charset: Option<String>,
44
45    command_charset: Option<String>,
46
47    language: Option<String>,
48
49    tagged_format: bool,
50
51    quiet_mode: bool,
52
53    #[cfg(all(feature = "lt2022_2", not(feature = "lt2021_2")))]
54    debug: bool,
55
56    #[cfg(not(feature = "lt2022_2"))]
57    debug_variable: Option<Vec<String>>,
58
59    display_version: bool,
60
61    display_help: bool,
62}
63
64impl GlobalOpts {
65    pub fn new() -> Self {
66        Self::default()
67    }
68
69    pub fn setup_args<'a>(&self, command: &'a mut Command) -> &'a mut Command {
70        if let Some(batch_size) = self.batch_size {
71            command.arg("-b").arg(batch_size.to_string());
72        }
73        if let Some(client) = self.client.as_ref() {
74            command.arg("-c").arg(client);
75        }
76        if let Some(dir) = self.dir.as_ref() {
77            command.arg("-d").arg(dir);
78        }
79        if self.progress_indicators {
80            command.arg("-I");
81        }
82        #[cfg(not(feature = "lt2019_1"))]
83        if self.standard_in {
84            command.arg("-i");
85        }
86        if self.marshalled_formatted {
87            command.arg("-G");
88        }
89        #[cfg(not(feature = "lt2020_1"))]
90        if self.json_formatted {
91            command.arg("-Mj");
92        }
93        if let Some(host) = self.host.as_ref() {
94            command.arg("-H").arg(host);
95        }
96        #[cfg(not(feature = "lt2019_1"))]
97        if self.standard_out {
98            command.arg("-o");
99        }
100        if let Some(port) = self.port.as_ref() {
101            command.arg("-p").arg(port);
102        }
103        if let Some(pass) = self.pass.as_ref() {
104            command.arg("-P").arg(pass);
105        }
106        if let Some(retries) = self.retries {
107            command.arg("-r").arg(retries.to_string());
108        }
109        if self.prepend_descriptive {
110            command.arg("-s");
111        }
112        if let Some(user) = self.user.as_ref() {
113            command.arg("-u").arg(user);
114        }
115        if let Some(argfile) = self.argfile.as_ref() {
116            command.arg("-x").arg(argfile);
117        }
118        if let Some(charset) = self.charset.as_ref() {
119            command.arg("-C").arg(charset);
120        }
121        if let Some(command_charset) = self.command_charset.as_ref() {
122            command.arg("-Q").arg(command_charset);
123        }
124        if let Some(language) = self.language.as_ref() {
125            command.arg("-L").arg(language);
126        }
127        if self.tagged_format {
128            command.arg("-z").arg("tag");
129        }
130        if self.quiet_mode {
131            command.arg("-q");
132        }
133        #[cfg(all(feature = "lt2022_2", not(feature = "lt2021_2")))]
134        if self.debug {
135            command.arg("-v");
136        }
137        #[cfg(not(feature = "lt2022_2"))]
138        if let Some(debug_variables) = self.debug_variable.as_ref() {
139            for debug_variable in debug_variables {
140                command.arg("-v").arg(debug_variable);
141            }
142        }
143        if self.display_version {
144            command.arg("-V");
145        }
146        if self.display_help {
147            command.arg("-h");
148        }
149        command
150    }
151
152    // pub fn setup_command_with<F>(&self, cmd: &str, handler: F) -> std::process::Command
153    // where
154    //     F: FnOnce(&mut std::process::Command),
155    // {
156    //     let mut command = std::process::Command::new(cmd);
157
158    //     handler(&mut command);
159    //     command
160    // }
161}
162
163impl GlobalOpts {
164    /// # Description
165    ///
166    /// -b batchsize
167    ///
168    /// Specifies a batch size (number of arguments) to use when processing a command
169    /// from a file with the -x argfile option. By default, the batch size is 128.
170    pub fn get_batch_size(&self) -> Option<&u32> {
171        self.batch_size.as_ref()
172    }
173    /// # Description
174    ///
175    /// -b batchsize
176    ///
177    /// Specifies a batch size (number of arguments) to use when processing a command
178    /// from a file with the -x argfile option. By default, the batch size is 128.
179    pub fn set_batch_size(&mut self, v: u32) -> &mut Self {
180        self.batch_size = Some(v);
181        self
182    }
183
184    /// # Description
185    ///
186    /// -b batchsize
187    ///
188    /// Specifies a batch size (number of arguments) to use when processing a command
189    /// from a file with the -x argfile option. By default, the batch size is 128.
190    pub fn batch_size(mut self, v: u32) -> Self {
191        self.batch_size = Some(v);
192        self
193    }
194
195    /// # Description
196    ///
197    /// -c client
198    ///
199    /// Overrides any P4CLIENT setting with the specified client name.
200    pub fn get_client(&self) -> Option<&String> {
201        self.client.as_ref()
202    }
203    /// # Description
204    ///
205    /// -c client
206    ///
207    /// Overrides any P4CLIENT setting with the specified client name.
208    pub fn set_client(&mut self, v: impl Into<String>) -> &mut Self {
209        self.client = Some(v.into());
210        self
211    }
212    /// # Description
213    ///
214    /// -c client
215    ///
216    /// Overrides any P4CLIENT setting with the specified client name.
217    pub fn client(mut self, v: impl Into<String>) -> Self {
218        self.client = Some(v.into());
219        self
220    }
221
222    /// # Description
223    ///
224    /// -d dir
225    ///
226    /// Overrides any PWD setting (current working directory) and replaces it with
227    /// the specified directory.
228    pub fn get_dir(&self) -> Option<&PathBuf> {
229        self.dir.as_ref()
230    }
231    /// # Description
232    ///
233    /// -d dir
234    ///
235    /// Overrides any PWD setting (current working directory) and replaces it with
236    /// the specified directory.
237    pub fn set_dir(&mut self, v: PathBuf) -> &mut Self {
238        self.dir = Some(v);
239        self
240    }
241    /// # Description
242    ///
243    /// -d dir
244    ///
245    /// Overrides any PWD setting (current working directory) and replaces it with
246    /// the specified directory.
247    pub fn dir(mut self, v: PathBuf) -> Self {
248        self.dir = Some(v);
249        self
250    }
251
252    /// # Description
253    ///
254    /// -I
255    ///
256    /// Specify that progress indicators, if available, are desired.
257    #[cfg_attr(
258        feature = "lt2014_2",
259        doc = "This flag is not compatible with the -s and -G options."
260    )]
261    #[cfg_attr(
262        all(feature = "lt2025_1", not(feature = "lt2014_2")),
263        doc = "This option is not compatible with the -s and -G options."
264    )]
265    #[cfg_attr(
266        not(feature = "lt2025_1"),
267        doc = "This option is not compatible with the -s and -G options.",
268        doc = "",
269        doc = "The progress indicator with the -I option is available for p4 -I move,",
270        doc = "p4 -I reconcile, p4 -I status, p4 -I submit, and p4 -I sync -q. For",
271        doc = "p4 -I reconcile and p4 -I status, the progress indicator shows four",
272        doc = "phases: reconcile add, reconcile edit, matching digest, and matching",
273        doc = "content. The add phase displays the number of directories scanned. All",
274        doc = "other phases show a percentage of files processed against total of",
275        doc = "candidate (deleted) files. For p4 -I move, the progress indicator shows",
276        doc = "two phases: matching digest, and matching content."
277    )]
278    pub fn get_progress_indicators(&self) -> bool {
279        self.progress_indicators
280    }
281
282    /// # Description
283    ///
284    /// -I
285    ///
286    /// Specify that progress indicators, if available, are desired.
287    #[cfg_attr(
288        feature = "lt2014_2",
289        doc = "This flag is not compatible with the -s and -G options."
290    )]
291    #[cfg_attr(
292        all(feature = "lt2025_1", not(feature = "lt2014_2")),
293        doc = "This option is not compatible with the -s and -G options."
294    )]
295    #[cfg_attr(
296        not(feature = "lt2025_1"),
297        doc = "This option is not compatible with the -s and -G options.",
298        doc = "",
299        doc = "The progress indicator with the -I option is available for p4 -I move,",
300        doc = "p4 -I reconcile, p4 -I status, p4 -I submit, and p4 -I sync -q. For",
301        doc = "p4 -I reconcile and p4 -I status, the progress indicator shows four",
302        doc = "phases: reconcile add, reconcile edit, matching digest, and matching",
303        doc = "content. The add phase displays the number of directories scanned. All",
304        doc = "other phases show a percentage of files processed against total of",
305        doc = "candidate (deleted) files. For p4 -I move, the progress indicator shows",
306        doc = "two phases: matching digest, and matching content."
307    )]
308    pub fn set_progress_indicators(&mut self, v: bool) -> &mut Self {
309        self.progress_indicators = v;
310        self
311    }
312
313    /// # Description
314    ///
315    /// -I
316    ///
317    /// Specify that progress indicators, if available, are desired.
318    #[cfg_attr(
319        feature = "lt2014_2",
320        doc = "This flag is not compatible with the -s and -G options."
321    )]
322    #[cfg_attr(
323        all(feature = "lt2025_1", not(feature = "lt2014_2")),
324        doc = "This option is not compatible with the -s and -G options."
325    )]
326    #[cfg_attr(
327        not(feature = "lt2025_1"),
328        doc = "This option is not compatible with the -s and -G options.",
329        doc = "",
330        doc = "The progress indicator with the -I option is available for p4 -I move,",
331        doc = "p4 -I reconcile, p4 -I status, p4 -I submit, and p4 -I sync -q. For",
332        doc = "p4 -I reconcile and p4 -I status, the progress indicator shows four",
333        doc = "phases: reconcile add, reconcile edit, matching digest, and matching",
334        doc = "content. The add phase displays the number of directories scanned. All",
335        doc = "other phases show a percentage of files processed against total of",
336        doc = "candidate (deleted) files. For p4 -I move, the progress indicator shows",
337        doc = "two phases: matching digest, and matching content."
338    )]
339    pub fn progress_indicators(mut self, v: bool) -> Self {
340        self.progress_indicators = v;
341        self
342    }
343
344    /// # Description
345    ///
346    /// -i
347    ///
348    /// Although not global, the -i and -o options work with forms and represent
349    /// standard in and standard out.
350    #[cfg(not(feature = "lt2019_1"))]
351    pub fn get_standard_in(&self) -> bool {
352        self.standard_in
353    }
354    /// # Description
355    ///
356    /// -i
357    ///
358    /// Although not global, the -i and -o options work with forms and represent
359    /// standard in and standard out.
360    #[cfg(not(feature = "lt2019_1"))]
361    pub fn set_standard_in(&mut self, v: bool) -> &mut Self {
362        self.standard_in = v;
363        self
364    }
365    /// # Description
366    ///
367    /// -i
368    ///
369    /// Although not global, the -i and -o options work with forms and represent
370    /// standard in and standard out.
371    #[cfg(not(feature = "lt2019_1"))]
372    pub fn standard_in(mut self, v: bool) -> Self {
373        self.standard_in = v;
374        self
375    }
376
377    /// # Description
378    ///
379    /// -G
380    ///
381    /// Causes all output (and batch input for form commands with -i) to be
382    #[cfg_attr(
383        feature = "lt2016_1",
384        doc = "formatted as marshalled Python dictionary objects. This is most often",
385        doc = "used when scripting."
386    )]
387    #[cfg_attr(
388        all(feature = "lt2018_1", not(feature = "lt2016_1")),
389        doc = "formatted as marshaled Python dictionary objects. This is most often",
390        doc = "used when scripting."
391    )]
392    #[cfg_attr(
393        all(feature = "lt2020_1", not(feature = "lt2018_1")),
394        doc = "formatted as marshaled Python dictionary objects. This is most often",
395        doc = "used when scripting. See Usage Notes."
396    )]
397    #[cfg_attr(
398        all(feature = "lt2024_1", not(feature = "lt2020_1")),
399        doc = "formatted as marshaled Python dictionary objects. This is most often",
400        doc = "used when scripting.",
401        doc = "",
402        doc = "# Note",
403        doc = "",
404        doc = "Use the -G option with the -z tag option. Otherwise the marshaled",
405        doc = "output might be invalid.",
406        doc = "",
407        doc = "See also the Usage Notes."
408    )]
409    #[cfg_attr(
410        not(feature = "lt2024_1"),
411        doc = "formatted as marshaled Python dictionary objects. This is most often",
412        doc = "used when scripting.",
413        doc = "",
414        doc = "# Note",
415        doc = "",
416        doc = "Use the -G option with the -z tag option. Otherwise the marshaled",
417        doc = "output might be invalid.",
418        doc = "",
419        doc = "See also the Usage notes."
420    )]
421    pub fn get_marshalled_formatted(&self) -> bool {
422        self.marshalled_formatted
423    }
424
425    /// # Description
426    ///
427    /// -G
428    ///
429    /// Causes all output (and batch input for form commands with -i) to be
430    #[cfg_attr(
431        feature = "lt2016_1",
432        doc = "formatted as marshalled Python dictionary objects. This is most often",
433        doc = "used when scripting."
434    )]
435    #[cfg_attr(
436        all(feature = "lt2018_1", not(feature = "lt2016_1")),
437        doc = "formatted as marshaled Python dictionary objects. This is most often",
438        doc = "used when scripting."
439    )]
440    #[cfg_attr(
441        all(feature = "lt2020_1", not(feature = "lt2018_1")),
442        doc = "formatted as marshaled Python dictionary objects. This is most often",
443        doc = "used when scripting. See Usage Notes."
444    )]
445    #[cfg_attr(
446        all(feature = "lt2024_1", not(feature = "lt2020_1")),
447        doc = "formatted as marshaled Python dictionary objects. This is most often",
448        doc = "used when scripting.",
449        doc = "",
450        doc = "# Note",
451        doc = "",
452        doc = "Use the -G option with the -z tag option. Otherwise the marshaled",
453        doc = "output might be invalid.",
454        doc = "",
455        doc = "See also the Usage Notes."
456    )]
457    #[cfg_attr(
458        not(feature = "lt2024_1"),
459        doc = "formatted as marshaled Python dictionary objects. This is most often",
460        doc = "used when scripting.",
461        doc = "",
462        doc = "# Note",
463        doc = "",
464        doc = "Use the -G option with the -z tag option. Otherwise the marshaled",
465        doc = "output might be invalid.",
466        doc = "",
467        doc = "See also the Usage notes."
468    )]
469    pub fn set_marshalled_formatted(&mut self, v: bool) -> &mut Self {
470        self.marshalled_formatted = v;
471        self
472    }
473
474    /// # Description
475    ///
476    /// -G
477    ///
478    /// Causes all output (and batch input for form commands with -i) to be
479    #[cfg_attr(
480        feature = "lt2016_1",
481        doc = "formatted as marshalled Python dictionary objects. This is most often",
482        doc = "used when scripting."
483    )]
484    #[cfg_attr(
485        all(feature = "lt2018_1", not(feature = "lt2016_1")),
486        doc = "formatted as marshaled Python dictionary objects. This is most often",
487        doc = "used when scripting."
488    )]
489    #[cfg_attr(
490        all(feature = "lt2020_1", not(feature = "lt2018_1")),
491        doc = "formatted as marshaled Python dictionary objects. This is most often",
492        doc = "used when scripting. See Usage Notes."
493    )]
494    #[cfg_attr(
495        all(feature = "lt2024_1", not(feature = "lt2020_1")),
496        doc = "formatted as marshaled Python dictionary objects. This is most often",
497        doc = "used when scripting.",
498        doc = "",
499        doc = "# Note",
500        doc = "",
501        doc = "Use the -G option with the -z tag option. Otherwise the marshaled",
502        doc = "output might be invalid.",
503        doc = "",
504        doc = "See also the Usage Notes."
505    )]
506    #[cfg_attr(
507        not(feature = "lt2024_1"),
508        doc = "formatted as marshaled Python dictionary objects. This is most often",
509        doc = "used when scripting.",
510        doc = "",
511        doc = "# Note",
512        doc = "",
513        doc = "Use the -G option with the -z tag option. Otherwise the marshaled",
514        doc = "output might be invalid.",
515        doc = "",
516        doc = "See also the Usage notes."
517    )]
518    pub fn marshalled_formatted(mut self, v: bool) -> Self {
519        self.marshalled_formatted = v;
520        self
521    }
522
523    /// # Description
524    ///
525    /// -Mj
526    ///
527    /// Formats output as line-delimited JSON objects, with non-UTF8 characters
528    /// replaced with U+FFFD
529    ///
530    /// # Note
531    ///
532    /// Use the -Mj option with the -z tag option. Otherwise the marshaled
533    /// output might be invalid.
534    #[cfg(not(feature = "lt2020_1"))]
535    pub fn get_json_formatted(&self) -> bool {
536        self.json_formatted
537    }
538    /// # Description
539    ///
540    /// -Mj
541    ///
542    /// Formats output as line-delimited JSON objects, with non-UTF8 characters
543    /// replaced with U+FFFD
544    ///
545    /// # Note
546    ///
547    /// Use the -Mj option with the -z tag option. Otherwise the marshaled
548    /// output might be invalid.
549    #[cfg(not(feature = "lt2020_1"))]
550    pub fn set_json_formatted(&mut self, v: bool) -> &mut Self {
551        self.json_formatted = v;
552        self
553    }
554    /// # Description
555    ///
556    /// -Mj
557    ///
558    /// Formats output as line-delimited JSON objects, with non-UTF8 characters
559    /// replaced with U+FFFD
560    ///
561    /// # Note
562    ///
563    /// Use the -Mj option with the -z tag option. Otherwise the marshaled
564    /// output might be invalid.
565    #[cfg(not(feature = "lt2020_1"))]
566    pub fn json_formatted(mut self, v: bool) -> Self {
567        self.json_formatted = v;
568        self
569    }
570
571    /// # Description
572    ///
573    /// -H host
574    ///
575    /// Overrides any P4HOST setting and replaces it with the specified hostname.
576    pub fn get_host(&self) -> Option<&String> {
577        self.host.as_ref()
578    }
579    /// # Description
580    ///
581    /// -H host
582    ///
583    /// Overrides any P4HOST setting and replaces it with the specified hostname.
584    pub fn set_host(&mut self, v: impl Into<String>) -> &mut Self {
585        self.host = Some(v.into());
586        self
587    }
588    /// # Description
589    ///
590    /// -H host
591    ///
592    /// Overrides any P4HOST setting and replaces it with the specified hostname.
593    pub fn host(mut self, v: impl Into<String>) -> Self {
594        self.host = Some(v.into());
595        self
596    }
597
598    /// # Description
599    ///
600    /// -o
601    ///
602    /// Although not global, the -i and -o options work with forms and represent
603    /// standard in and standard out.
604    #[cfg(not(feature = "lt2019_1"))]
605    pub fn get_standard_out(&self) -> bool {
606        self.standard_out
607    }
608    /// # Description
609    ///
610    /// -o
611    ///
612    /// Although not global, the -i and -o options work with forms and represent
613    /// standard in and standard out.
614    #[cfg(not(feature = "lt2019_1"))]
615    pub fn set_standard_out(&mut self, v: bool) -> &mut Self {
616        self.standard_out = v;
617        self
618    }
619    /// # Description
620    ///
621    /// -o
622    ///
623    /// Although not global, the -i and -o options work with forms and represent
624    /// standard in and standard out.
625    #[cfg(not(feature = "lt2019_1"))]
626    pub fn standard_out(mut self, v: bool) -> Self {
627        self.standard_out = v;
628        self
629    }
630
631    /// # Description
632    ///
633    /// -p port
634    ///
635    /// Overrides any P4PORT setting with the specified protocol:host:port.
636    pub fn get_port(&self) -> Option<&String> {
637        self.port.as_ref()
638    }
639    /// # Description
640    ///
641    /// -p port
642    ///
643    /// Overrides any P4PORT setting with the specified protocol:host:port.
644    pub fn set_port(&mut self, v: impl Into<String>) -> &mut Self {
645        self.port = Some(v.into());
646        self
647    }
648    /// # Description
649    ///
650    /// -p port
651    ///
652    /// Overrides any P4PORT setting with the specified protocol:host:port.
653    pub fn port(mut self, v: impl Into<String>) -> Self {
654        self.port = Some(v.into());
655        self
656    }
657
658    /// # Description
659    ///
660    /// -P pass
661    ///
662    #[cfg_attr(
663        feature = "lt2021_2",
664        doc = "Overrides any P4PASSWD setting with the specified password."
665    )]
666    #[cfg_attr(
667        not(feature = "lt2021_2"),
668        doc = "Enables a password (or ticket) to be passed on the command line, thus",
669        doc = "bypassing the password associated with P4PASSWD. If a valid ticket exists,",
670        doc = "using this option with an invalid pass causes access to be granted by the",
671        doc = "valid ticket."
672    )]
673    pub fn get_pass(&self) -> Option<&String> {
674        self.pass.as_ref()
675    }
676
677    /// # Description
678    ///
679    /// -P pass
680    ///
681    #[cfg_attr(
682        feature = "lt2021_2",
683        doc = "Overrides any P4PASSWD setting with the specified password."
684    )]
685    #[cfg_attr(
686        not(feature = "lt2021_2"),
687        doc = "Enables a password (or ticket) to be passed on the command line, thus",
688        doc = "bypassing the password associated with P4PASSWD. If a valid ticket exists,",
689        doc = "using this option with an invalid pass causes access to be granted by the",
690        doc = "valid ticket."
691    )]
692    pub fn set_pass(&mut self, v: impl Into<String>) -> &mut Self {
693        self.pass = Some(v.into());
694        self
695    }
696
697    /// # Description
698    ///
699    /// -P pass
700    ///
701    #[cfg_attr(
702        feature = "lt2021_2",
703        doc = "Overrides any P4PASSWD setting with the specified password."
704    )]
705    #[cfg_attr(
706        not(feature = "lt2021_2"),
707        doc = "Enables a password (or ticket) to be passed on the command line, thus",
708        doc = "bypassing the password associated with P4PASSWD. If a valid ticket exists,",
709        doc = "using this option with an invalid pass causes access to be granted by the",
710        doc = "valid ticket."
711    )]
712    pub fn pass(mut self, v: impl Into<String>) -> Self {
713        self.pass = Some(v.into());
714        self
715    }
716
717    /// # Description
718    ///
719    /// -r retries
720    ///
721    /// Specifies the number of times to retry a command (notably, p4 sync) if
722    /// the network times out.
723    pub fn get_retries(&self) -> Option<&u32> {
724        self.retries.as_ref()
725    }
726    /// # Description
727    ///
728    /// -r retries
729    ///
730    /// Specifies the number of times to retry a command (notably, p4 sync) if
731    /// the network times out.
732    pub fn set_retries(&mut self, v: u32) -> &mut Self {
733        self.retries = Some(v);
734        self
735    }
736    /// # Description
737    ///
738    /// -r retries
739    ///
740    /// Specifies the number of times to retry a command (notably, p4 sync) if
741    /// the network times out.
742    pub fn retries(mut self, v: u32) -> Self {
743        self.retries = Some(v);
744        self
745    }
746
747    /// # Description
748    ///
749    /// -s
750    ///
751    /// Prepends a descriptive field (for example, text:, info:, error:, exit:)
752    /// to each line of output produced by a
753    #[cfg_attr(
754        feature = "lt2017_2",
755        doc = "Perforce command. This is most often",
756        doc = "used when scripting."
757    )]
758    #[cfg_attr(
759        all(feature = "lt2019_1", not(feature = "lt2017_2")),
760        doc = "Helix Server command. This is most",
761        doc = "often used when scripting."
762    )]
763    #[cfg_attr(
764        all(feature = "lt2021_1", not(feature = "lt2019_1")),
765        doc = "Helix server command. This is most",
766        doc = "often used when scripting."
767    )]
768    #[cfg_attr(
769        all(feature = "lt2024_1", not(feature = "lt2021_1")),
770        doc = "Helix Server command. This is most",
771        doc = "often used when scripting."
772    )]
773    #[cfg_attr(
774        all(feature = "lt2024_2", not(feature = "lt2024_1")),
775        doc = "Helix Core Server command. This is",
776        doc = "most often used when scripting."
777    )]
778    #[cfg_attr(
779        not(feature = "lt2024_2"),
780        doc = "P4 Server command. This is most",
781        doc = "often used when scripting."
782    )]
783    pub fn get_prepend_descriptive(&self) -> bool {
784        self.prepend_descriptive
785    }
786
787    /// # Description
788    ///
789    /// -s
790    ///
791    /// Prepends a descriptive field (for example, text:, info:, error:, exit:)
792    /// to each line of output produced by a
793    #[cfg_attr(
794        feature = "lt2017_2",
795        doc = "Perforce command. This is most often",
796        doc = "used when scripting."
797    )]
798    #[cfg_attr(
799        all(feature = "lt2019_1", not(feature = "lt2017_2")),
800        doc = "Helix Server command. This is most",
801        doc = "often used when scripting."
802    )]
803    #[cfg_attr(
804        all(feature = "lt2021_1", not(feature = "lt2019_1")),
805        doc = "Helix server command. This is most",
806        doc = "often used when scripting."
807    )]
808    #[cfg_attr(
809        all(feature = "lt2024_1", not(feature = "lt2021_1")),
810        doc = "Helix Server command. This is most",
811        doc = "often used when scripting."
812    )]
813    #[cfg_attr(
814        all(feature = "lt2024_2", not(feature = "lt2024_1")),
815        doc = "Helix Core Server command. This is",
816        doc = "most often used when scripting."
817    )]
818    #[cfg_attr(
819        not(feature = "lt2024_2"),
820        doc = "P4 Server command. This is most",
821        doc = "often used when scripting."
822    )]
823    pub fn set_prepend_descriptive(&mut self, v: bool) -> &mut Self {
824        self.prepend_descriptive = v;
825        self
826    }
827
828    /// # Description
829    ///
830    /// -s
831    ///
832    /// Prepends a descriptive field (for example, text:, info:, error:, exit:)
833    /// to each line of output produced by a
834    #[cfg_attr(
835        feature = "lt2017_2",
836        doc = "Perforce command. This is most often",
837        doc = "used when scripting."
838    )]
839    #[cfg_attr(
840        all(feature = "lt2019_1", not(feature = "lt2017_2")),
841        doc = "Helix Server command. This is most",
842        doc = "often used when scripting."
843    )]
844    #[cfg_attr(
845        all(feature = "lt2021_1", not(feature = "lt2019_1")),
846        doc = "Helix server command. This is most",
847        doc = "often used when scripting."
848    )]
849    #[cfg_attr(
850        all(feature = "lt2024_1", not(feature = "lt2021_1")),
851        doc = "Helix Server command. This is most",
852        doc = "often used when scripting."
853    )]
854    #[cfg_attr(
855        all(feature = "lt2024_2", not(feature = "lt2024_1")),
856        doc = "Helix Core Server command. This is",
857        doc = "most often used when scripting."
858    )]
859    #[cfg_attr(
860        not(feature = "lt2024_2"),
861        doc = "P4 Server command. This is most",
862        doc = "often used when scripting."
863    )]
864    pub fn prepend_descriptive(mut self, v: bool) -> Self {
865        self.prepend_descriptive = v;
866        self
867    }
868
869    /// # Description
870    ///
871    /// -u user
872    ///
873    /// Overrides any P4USER, USER, or USERNAME setting with the specified user name.
874    pub fn get_user(&self) -> Option<&String> {
875        self.user.as_ref()
876    }
877    /// # Description
878    ///
879    /// -u user
880    ///
881    /// Overrides any P4USER, USER, or USERNAME setting with the specified user name.
882    pub fn set_user(&mut self, v: impl Into<String>) -> &mut Self {
883        self.user = Some(v.into());
884        self
885    }
886    /// # Description
887    ///
888    /// -u user
889    ///
890    /// Overrides any P4USER, USER, or USERNAME setting with the specified user name.
891    pub fn user(mut self, v: impl Into<String>) -> Self {
892        self.user = Some(v.into());
893        self
894    }
895
896    /// # Description
897    ///
898    /// -x argfile
899    ///
900    /// Instructs
901    #[cfg_attr(
902        feature = "lt2017_2",
903        doc = "Perforce to read arguments, one per line, from the specified",
904        doc = "file. If file is a single hyphen (-), then standard input is read."
905    )]
906    #[cfg_attr(
907        all(feature = "lt2018_1", not(feature = "lt2017_2")),
908        doc = "Helix Server to read arguments, one per line, from the",
909        doc = "specified file. If file is a single hyphen (-), then standard input is",
910        doc = "read."
911    )]
912    #[cfg_attr(
913        all(feature = "lt2019_1", not(feature = "lt2018_1")),
914        doc = "Helix Server to read arguments, one per line, from the",
915        doc = "specified file. If argfile is a single hyphen (-), instructs Helix",
916        doc = "Server to read from standard input instead of from a file."
917    )]
918    #[cfg_attr(
919        all(feature = "lt2021_1", not(feature = "lt2019_1")),
920        doc = "Helix server to read arguments, one per line, from the",
921        doc = "specified file. If argfile is a single hyphen (-), instructs Helix",
922        doc = "server to read from standard input instead of from a file."
923    )]
924    #[cfg_attr(
925        all(feature = "lt2024_1", not(feature = "lt2021_1")),
926        doc = "Helix Server to read arguments, one per line, from the",
927        doc = "specified file. If argfile is a single hyphen (-), instructs Helix",
928        doc = "Server to read from standard input instead of from a file."
929    )]
930    #[cfg_attr(
931        all(feature = "lt2024_2", not(feature = "lt2024_1")),
932        doc = "Helix Core Server to read arguments, one per line, from the",
933        doc = "specified file. If argfile is a single hyphen (-), instructs Helix Core",
934        doc = "Server to read from standard input instead of from a file."
935    )]
936    #[cfg_attr(
937        not(feature = "lt2024_2"),
938        doc = "P4 Server to read arguments, one per line, from the specified",
939        doc = "file. If argfile is a single hyphen (-), instructs P4 Server to read from",
940        doc = "standard input instead of from a file."
941    )]
942    pub fn get_argfile(&self) -> Option<&PathBuf> {
943        self.argfile.as_ref()
944    }
945
946    /// # Description
947    ///
948    /// -x argfile
949    ///
950    /// Instructs
951    #[cfg_attr(
952        feature = "lt2017_2",
953        doc = "Perforce to read arguments, one per line, from the specified",
954        doc = "file. If file is a single hyphen (-), then standard input is read."
955    )]
956    #[cfg_attr(
957        all(feature = "lt2018_1", not(feature = "lt2017_2")),
958        doc = "Helix Server to read arguments, one per line, from the",
959        doc = "specified file. If file is a single hyphen (-), then standard input is",
960        doc = "read."
961    )]
962    #[cfg_attr(
963        all(feature = "lt2019_1", not(feature = "lt2018_1")),
964        doc = "Helix Server to read arguments, one per line, from the",
965        doc = "specified file. If argfile is a single hyphen (-), instructs Helix",
966        doc = "Server to read from standard input instead of from a file."
967    )]
968    #[cfg_attr(
969        all(feature = "lt2021_1", not(feature = "lt2019_1")),
970        doc = "Helix server to read arguments, one per line, from the",
971        doc = "specified file. If argfile is a single hyphen (-), instructs Helix",
972        doc = "server to read from standard input instead of from a file."
973    )]
974    #[cfg_attr(
975        all(feature = "lt2024_1", not(feature = "lt2021_1")),
976        doc = "Helix Server to read arguments, one per line, from the",
977        doc = "specified file. If argfile is a single hyphen (-), instructs Helix",
978        doc = "Server to read from standard input instead of from a file."
979    )]
980    #[cfg_attr(
981        all(feature = "lt2024_2", not(feature = "lt2024_1")),
982        doc = "Helix Core Server to read arguments, one per line, from the",
983        doc = "specified file. If argfile is a single hyphen (-), instructs Helix Core",
984        doc = "Server to read from standard input instead of from a file."
985    )]
986    #[cfg_attr(
987        not(feature = "lt2024_2"),
988        doc = "P4 Server to read arguments, one per line, from the specified",
989        doc = "file. If argfile is a single hyphen (-), instructs P4 Server to read from",
990        doc = "standard input instead of from a file."
991    )]
992    pub fn set_argfile(&mut self, v: PathBuf) -> &mut Self {
993        self.argfile = Some(v);
994        self
995    }
996
997    /// # Description
998    ///
999    /// -x argfile
1000    ///
1001    /// Instructs
1002    #[cfg_attr(
1003        feature = "lt2017_2",
1004        doc = "Perforce to read arguments, one per line, from the specified",
1005        doc = "file. If file is a single hyphen (-), then standard input is read."
1006    )]
1007    #[cfg_attr(
1008        all(feature = "lt2018_1", not(feature = "lt2017_2")),
1009        doc = "Helix Server to read arguments, one per line, from the",
1010        doc = "specified file. If file is a single hyphen (-), then standard input is",
1011        doc = "read."
1012    )]
1013    #[cfg_attr(
1014        all(feature = "lt2019_1", not(feature = "lt2018_1")),
1015        doc = "Helix Server to read arguments, one per line, from the",
1016        doc = "specified file. If argfile is a single hyphen (-), instructs Helix",
1017        doc = "Server to read from standard input instead of from a file."
1018    )]
1019    #[cfg_attr(
1020        all(feature = "lt2021_1", not(feature = "lt2019_1")),
1021        doc = "Helix server to read arguments, one per line, from the",
1022        doc = "specified file. If argfile is a single hyphen (-), instructs Helix",
1023        doc = "server to read from standard input instead of from a file."
1024    )]
1025    #[cfg_attr(
1026        all(feature = "lt2024_1", not(feature = "lt2021_1")),
1027        doc = "Helix Server to read arguments, one per line, from the",
1028        doc = "specified file. If argfile is a single hyphen (-), instructs Helix",
1029        doc = "Server to read from standard input instead of from a file."
1030    )]
1031    #[cfg_attr(
1032        all(feature = "lt2024_2", not(feature = "lt2024_1")),
1033        doc = "Helix Core Server to read arguments, one per line, from the",
1034        doc = "specified file. If argfile is a single hyphen (-), instructs Helix Core",
1035        doc = "Server to read from standard input instead of from a file."
1036    )]
1037    #[cfg_attr(
1038        not(feature = "lt2024_2"),
1039        doc = "P4 Server to read arguments, one per line, from the specified",
1040        doc = "file. If argfile is a single hyphen (-), instructs P4 Server to read from",
1041        doc = "standard input instead of from a file."
1042    )]
1043    pub fn argfile(mut self, v: PathBuf) -> Self {
1044        self.argfile = Some(v);
1045        self
1046    }
1047
1048    /// # Description
1049    ///
1050    /// -C charset
1051    ///
1052    /// Overrides any P4CHARSET setting with the specified character set.
1053    pub fn get_charset(&self) -> Option<&String> {
1054        self.charset.as_ref()
1055    }
1056    /// # Description
1057    ///
1058    /// -C charset
1059    ///
1060    /// Overrides any P4CHARSET setting with the specified character set.
1061    pub fn set_charset(&mut self, v: impl Into<String>) -> &mut Self {
1062        self.charset = Some(v.into());
1063        self
1064    }
1065    /// # Description
1066    ///
1067    /// -C charset
1068    ///
1069    /// Overrides any P4CHARSET setting with the specified character set.
1070    pub fn charset(mut self, v: impl Into<String>) -> Self {
1071        self.charset = Some(v.into());
1072        self
1073    }
1074
1075    /// # Description
1076    ///
1077    /// -Q charset
1078    ///
1079    /// Overrides any P4COMMANDCHARSET setting with the specified character set.
1080    pub fn get_command_charset(&self) -> Option<&String> {
1081        self.command_charset.as_ref()
1082    }
1083    /// # Description
1084    ///
1085    /// -Q charset
1086    ///
1087    /// Overrides any P4COMMANDCHARSET setting with the specified character set.
1088    pub fn set_command_charset(&mut self, v: impl Into<String>) -> &mut Self {
1089        self.command_charset = Some(v.into());
1090        self
1091    }
1092    /// # Description
1093    ///
1094    /// -Q charset
1095    ///
1096    /// Overrides any P4COMMANDCHARSET setting with the specified character set.
1097    pub fn command_charset(mut self, v: impl Into<String>) -> Self {
1098        self.command_charset = Some(v.into());
1099        self
1100    }
1101
1102    /// # Description
1103    ///
1104    /// -L language
1105    ///
1106    /// This feature is reserved for system integrators.
1107    pub fn get_language(&self) -> Option<&String> {
1108        self.language.as_ref()
1109    }
1110    /// # Description
1111    ///
1112    /// -L language
1113    ///
1114    /// This feature is reserved for system integrators.
1115    pub fn set_language(&mut self, v: impl Into<String>) -> &mut Self {
1116        self.language = Some(v.into());
1117        self
1118    }
1119    /// # Description
1120    ///
1121    /// -L language
1122    ///
1123    /// This feature is reserved for system integrators.
1124    pub fn language(mut self, v: impl Into<String>) -> Self {
1125        self.language = Some(v.into());
1126        self
1127    }
1128
1129    /// # Description
1130    ///
1131    /// -z tag
1132    ///
1133    /// Causes output of many reporting commands to be in the same tagged format
1134    /// as that generated by p4 fstat.
1135    #[cfg_attr(
1136        all(feature = "lt2022_1", not(feature = "lt2020_1")),
1137        doc = "",
1138        doc = "# Note",
1139        doc = "",
1140        doc = "Use this option for all marshaled output, such as that of -G and -Mj.",
1141        doc = "Otherwise the marshaled output might be invalid."
1142    )]
1143    #[cfg_attr(
1144        all(feature = "lt2023_1", not(feature = "lt2022_1")),
1145        doc = "",
1146        doc = "# Note",
1147        doc = "",
1148        doc = "Use this option for all marshaled output, such as that of -G and -Mj.",
1149        doc = "Otherwise the marshaled output might be invalid.",
1150        doc = "",
1151        doc = "See also the Timestamp information."
1152    )]
1153    #[cfg_attr(
1154        all(feature = "lt2025_2", not(feature = "lt2023_1")),
1155        doc = "",
1156        doc = "# Note",
1157        doc = "",
1158        doc = "Use this option for all marshaled output, such as that of -G and -Mj.",
1159        doc = "Otherwise the marshaled output might be invalid.",
1160        doc = "",
1161        doc = "See also the Timestamp and Unix epoch time information."
1162    )]
1163    #[cfg_attr(
1164        not(feature = "lt2025_2"),
1165        doc = "",
1166        doc = "# Note",
1167        doc = "",
1168        doc = "Use this option for all marshaled output, such as that of -G and -Mj.",
1169        doc = "Otherwise the marshaled output might be invalid.",
1170        doc = "",
1171        doc = "See also the Timestamp and Unix epoch information."
1172    )]
1173    pub fn get_tagged_format(&self) -> bool {
1174        self.tagged_format
1175    }
1176
1177    /// # Description
1178    ///
1179    /// -z tag
1180    ///
1181    /// Causes output of many reporting commands to be in the same tagged format
1182    /// as that generated by p4 fstat.
1183    #[cfg_attr(
1184        all(feature = "lt2022_1", not(feature = "lt2020_1")),
1185        doc = "",
1186        doc = "# Note",
1187        doc = "",
1188        doc = "Use this option for all marshaled output, such as that of -G and -Mj.",
1189        doc = "Otherwise the marshaled output might be invalid."
1190    )]
1191    #[cfg_attr(
1192        all(feature = "lt2023_1", not(feature = "lt2022_1")),
1193        doc = "",
1194        doc = "# Note",
1195        doc = "",
1196        doc = "Use this option for all marshaled output, such as that of -G and -Mj.",
1197        doc = "Otherwise the marshaled output might be invalid.",
1198        doc = "",
1199        doc = "See also the Timestamp information."
1200    )]
1201    #[cfg_attr(
1202        all(feature = "lt2025_2", not(feature = "lt2023_1")),
1203        doc = "",
1204        doc = "# Note",
1205        doc = "",
1206        doc = "Use this option for all marshaled output, such as that of -G and -Mj.",
1207        doc = "Otherwise the marshaled output might be invalid.",
1208        doc = "",
1209        doc = "See also the Timestamp and Unix epoch time information."
1210    )]
1211    #[cfg_attr(
1212        not(feature = "lt2025_2"),
1213        doc = "",
1214        doc = "# Note",
1215        doc = "",
1216        doc = "Use this option for all marshaled output, such as that of -G and -Mj.",
1217        doc = "Otherwise the marshaled output might be invalid.",
1218        doc = "",
1219        doc = "See also the Timestamp and Unix epoch information."
1220    )]
1221    pub fn set_tagged_format(&mut self, v: bool) -> &mut Self {
1222        self.tagged_format = v;
1223        self
1224    }
1225
1226    /// # Description
1227    ///
1228    /// -z tag
1229    ///
1230    /// Causes output of many reporting commands to be in the same tagged format
1231    /// as that generated by p4 fstat.
1232    #[cfg_attr(
1233        all(feature = "lt2022_1", not(feature = "lt2020_1")),
1234        doc = "",
1235        doc = "# Note",
1236        doc = "",
1237        doc = "Use this option for all marshaled output, such as that of -G and -Mj.",
1238        doc = "Otherwise the marshaled output might be invalid."
1239    )]
1240    #[cfg_attr(
1241        all(feature = "lt2023_1", not(feature = "lt2022_1")),
1242        doc = "",
1243        doc = "# Note",
1244        doc = "",
1245        doc = "Use this option for all marshaled output, such as that of -G and -Mj.",
1246        doc = "Otherwise the marshaled output might be invalid.",
1247        doc = "",
1248        doc = "See also the Timestamp information."
1249    )]
1250    #[cfg_attr(
1251        all(feature = "lt2025_2", not(feature = "lt2023_1")),
1252        doc = "",
1253        doc = "# Note",
1254        doc = "",
1255        doc = "Use this option for all marshaled output, such as that of -G and -Mj.",
1256        doc = "Otherwise the marshaled output might be invalid.",
1257        doc = "",
1258        doc = "See also the Timestamp and Unix epoch time information."
1259    )]
1260    #[cfg_attr(
1261        not(feature = "lt2025_2"),
1262        doc = "",
1263        doc = "# Note",
1264        doc = "",
1265        doc = "Use this option for all marshaled output, such as that of -G and -Mj.",
1266        doc = "Otherwise the marshaled output might be invalid.",
1267        doc = "",
1268        doc = "See also the Timestamp and Unix epoch information."
1269    )]
1270    pub fn tagged_format(mut self, v: bool) -> Self {
1271        self.tagged_format = v;
1272        self
1273    }
1274
1275    /// # Description
1276    ///
1277    /// -q
1278    ///
1279    #[cfg_attr(
1280        feature = "lt2018_1",
1281        doc = "Quiet mode; suppress all informational message and report only warnings",
1282        doc = "or errors."
1283    )]
1284    #[cfg_attr(
1285        not(feature = "lt2018_1"),
1286        doc = "Quiet mode, which suppresses informational messages and reports only",
1287        doc = "warnings or errors."
1288    )]
1289    pub fn get_quiet_mode(&self) -> bool {
1290        self.quiet_mode
1291    }
1292
1293    /// # Description
1294    ///
1295    /// -q
1296    ///
1297    #[cfg_attr(
1298        feature = "lt2018_1",
1299        doc = "Quiet mode; suppress all informational message and report only warnings",
1300        doc = "or errors."
1301    )]
1302    #[cfg_attr(
1303        not(feature = "lt2018_1"),
1304        doc = "Quiet mode, which suppresses informational messages and reports only",
1305        doc = "warnings or errors."
1306    )]
1307    pub fn set_quiet_mode(&mut self, v: bool) -> &mut Self {
1308        self.quiet_mode = v;
1309        self
1310    }
1311
1312    /// # Description
1313    ///
1314    /// -q
1315    ///
1316    #[cfg_attr(
1317        feature = "lt2018_1",
1318        doc = "Quiet mode; suppress all informational message and report only warnings",
1319        doc = "or errors."
1320    )]
1321    #[cfg_attr(
1322        not(feature = "lt2018_1"),
1323        doc = "Quiet mode, which suppresses informational messages and reports only",
1324        doc = "warnings or errors."
1325    )]
1326    pub fn quiet_mode(mut self, v: bool) -> Self {
1327        self.quiet_mode = v;
1328        self
1329    }
1330
1331    /// # Description
1332    ///
1333    /// -v
1334    ///
1335    /// Debug modes
1336    #[cfg(all(feature = "lt2022_2", not(feature = "lt2021_2")))]
1337    pub fn get_debug(&self) -> bool {
1338        self.debug
1339    }
1340    /// # Description
1341    ///
1342    /// -v var
1343    ///
1344    /// Debug level or configurable represented by var, such as: p4 -v 1 info or
1345    /// p4 -v net.autotune=0 info. This option can be specified more than once;
1346    /// each call appends another var.
1347    #[cfg(not(feature = "lt2022_2"))]
1348    pub fn get_debug_variable(&self) -> Option<&[String]> {
1349        self.debug_variable.as_deref()
1350    }
1351    /// # Description
1352    ///
1353    /// -v
1354    ///
1355    /// Debug modes
1356    #[cfg(all(feature = "lt2022_2", not(feature = "lt2021_2")))]
1357    pub fn set_debug(&mut self, v: bool) -> &mut Self {
1358        self.debug = v;
1359        self
1360    }
1361    /// # Description
1362    ///
1363    /// -v var
1364    ///
1365    /// Debug level or configurable represented by var, such as: p4 -v 1 info or
1366    /// p4 -v net.autotune=0 info. This option can be specified more than once;
1367    /// each call appends another var.
1368    #[cfg(not(feature = "lt2022_2"))]
1369    pub fn set_debug_variable(&mut self, v: impl Into<String>) -> &mut Self {
1370        self.debug_variable
1371            .get_or_insert_with(Vec::new)
1372            .push(v.into());
1373        self
1374    }
1375    /// # Description
1376    ///
1377    /// -v
1378    ///
1379    /// Debug modes
1380    #[cfg(all(feature = "lt2022_2", not(feature = "lt2021_2")))]
1381    pub fn debug(mut self, v: bool) -> Self {
1382        self.debug = v;
1383        self
1384    }
1385    /// # Description
1386    ///
1387    /// -v var
1388    ///
1389    /// Debug level or configurable represented by var, such as: p4 -v 1 info or
1390    /// p4 -v net.autotune=0 info. This option can be specified more than once;
1391    /// each call appends another var.
1392    #[cfg(not(feature = "lt2022_2"))]
1393    pub fn debug_variable(mut self, v: impl Into<String>) -> Self {
1394        self.debug_variable
1395            .get_or_insert_with(Vec::new)
1396            .push(v.into());
1397        self
1398    }
1399
1400    /// # Description
1401    ///
1402    /// -V
1403    ///
1404    /// Displays the version of the p4 application and exits.
1405    pub fn get_display_version(&self) -> bool {
1406        self.display_version
1407    }
1408    /// # Description
1409    ///
1410    /// -V
1411    ///
1412    /// Displays the version of the p4 application and exits.
1413    pub fn set_display_version(&mut self, v: bool) -> &mut Self {
1414        self.display_version = v;
1415        self
1416    }
1417    /// # Description
1418    ///
1419    /// -V
1420    ///
1421    /// Displays the version of the p4 application and exits.
1422    pub fn display_version(mut self, v: bool) -> Self {
1423        self.display_version = v;
1424        self
1425    }
1426
1427    /// # Description
1428    ///
1429    /// -h
1430    ///
1431    /// Displays basic usage information and exits.
1432    pub fn get_display_help(&self) -> bool {
1433        self.display_help
1434    }
1435    /// # Description
1436    ///
1437    /// -h
1438    ///
1439    /// Displays basic usage information and exits.
1440    pub fn set_display_help(&mut self, v: bool) -> &mut Self {
1441        self.display_help = v;
1442        self
1443    }
1444    /// # Description
1445    ///
1446    /// -h
1447    ///
1448    /// Displays basic usage information and exits.
1449    pub fn display_help(mut self, v: bool) -> Self {
1450        self.display_help = v;
1451        self
1452    }
1453}
1454
1455#[cfg(test)]
1456mod tests {
1457    use super::*;
1458    use crate::cmd::args_of;
1459    use std::path::PathBuf;
1460    use std::process::Command;
1461
1462    /// Every global option is injected exactly once in the order documented in
1463    /// [`GlobalOpts::setup_args`].
1464    #[test]
1465    fn options_are_injected_in_documented_order() {
1466        let mut global_opts = GlobalOpts::new();
1467        global_opts
1468            .set_batch_size(256)
1469            .set_client("ws")
1470            .set_dir(PathBuf::from("C:\\tmp"))
1471            .set_progress_indicators(true)
1472            .set_marshalled_formatted(true)
1473            .set_host("helix.example")
1474            .set_port("localhost:1666")
1475            .set_pass("secret")
1476            .set_retries(1)
1477            .set_prepend_descriptive(true)
1478            .set_user("bruno")
1479            .set_argfile(PathBuf::from("args.txt"))
1480            .set_charset("utf8")
1481            .set_command_charset("utf8")
1482            .set_language("en")
1483            .set_tagged_format(true)
1484            .set_quiet_mode(true)
1485            .set_display_version(true)
1486            .set_display_help(true);
1487        #[cfg(not(feature = "lt2019_1"))]
1488        global_opts.set_standard_in(true).set_standard_out(true);
1489        #[cfg(not(feature = "lt2020_1"))]
1490        global_opts.set_json_formatted(true);
1491        #[cfg(not(feature = "lt2022_2"))]
1492        global_opts.set_debug_variable("net.autotune=0");
1493        #[cfg(all(feature = "lt2022_2", not(feature = "lt2021_2")))]
1494        global_opts.set_debug(true);
1495
1496        let mut expected: Vec<&str> = vec!["-b", "256", "-c", "ws", "-d", "C:\\tmp", "-I"];
1497        #[cfg(not(feature = "lt2019_1"))]
1498        expected.push("-i");
1499        expected.push("-G");
1500        #[cfg(not(feature = "lt2020_1"))]
1501        expected.push("-Mj");
1502        expected.extend(["-H", "helix.example"]);
1503        #[cfg(not(feature = "lt2019_1"))]
1504        expected.push("-o");
1505        expected.extend([
1506            "-p",
1507            "localhost:1666",
1508            "-P",
1509            "secret",
1510            "-r",
1511            "1",
1512            "-s",
1513            "-u",
1514            "bruno",
1515            "-x",
1516            "args.txt",
1517            "-C",
1518            "utf8",
1519            "-Q",
1520            "utf8",
1521            "-L",
1522            "en",
1523            "-z",
1524            "tag",
1525            "-q",
1526        ]);
1527        #[cfg(not(feature = "lt2022_2"))]
1528        expected.extend(["-v", "net.autotune=0"]);
1529        #[cfg(all(feature = "lt2022_2", not(feature = "lt2021_2")))]
1530        expected.push("-v");
1531        expected.extend(["-V", "-h"]);
1532
1533        let mut command = Command::new("p4");
1534        global_opts.setup_args(&mut command);
1535
1536        assert_eq!(args_of(&command), expected);
1537    }
1538}