1use std::{path::PathBuf, process::Command};
2
3#[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 }
162
163impl GlobalOpts {
164 pub fn get_batch_size(&self) -> Option<&u32> {
171 self.batch_size.as_ref()
172 }
173 pub fn set_batch_size(&mut self, v: u32) -> &mut Self {
180 self.batch_size = Some(v);
181 self
182 }
183
184 pub fn batch_size(mut self, v: u32) -> Self {
191 self.batch_size = Some(v);
192 self
193 }
194
195 pub fn get_client(&self) -> Option<&String> {
201 self.client.as_ref()
202 }
203 pub fn set_client(&mut self, v: impl Into<String>) -> &mut Self {
209 self.client = Some(v.into());
210 self
211 }
212 pub fn client(mut self, v: impl Into<String>) -> Self {
218 self.client = Some(v.into());
219 self
220 }
221
222 pub fn get_dir(&self) -> Option<&PathBuf> {
229 self.dir.as_ref()
230 }
231 pub fn set_dir(&mut self, v: PathBuf) -> &mut Self {
238 self.dir = Some(v);
239 self
240 }
241 pub fn dir(mut self, v: PathBuf) -> Self {
248 self.dir = Some(v);
249 self
250 }
251
252 #[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 #[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 #[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 #[cfg(not(feature = "lt2019_1"))]
351 pub fn get_standard_in(&self) -> bool {
352 self.standard_in
353 }
354 #[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 #[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 #[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 #[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 #[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 #[cfg(not(feature = "lt2020_1"))]
535 pub fn get_json_formatted(&self) -> bool {
536 self.json_formatted
537 }
538 #[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 #[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 pub fn get_host(&self) -> Option<&String> {
577 self.host.as_ref()
578 }
579 pub fn set_host(&mut self, v: impl Into<String>) -> &mut Self {
585 self.host = Some(v.into());
586 self
587 }
588 pub fn host(mut self, v: impl Into<String>) -> Self {
594 self.host = Some(v.into());
595 self
596 }
597
598 #[cfg(not(feature = "lt2019_1"))]
605 pub fn get_standard_out(&self) -> bool {
606 self.standard_out
607 }
608 #[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 #[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 pub fn get_port(&self) -> Option<&String> {
637 self.port.as_ref()
638 }
639 pub fn set_port(&mut self, v: impl Into<String>) -> &mut Self {
645 self.port = Some(v.into());
646 self
647 }
648 pub fn port(mut self, v: impl Into<String>) -> Self {
654 self.port = Some(v.into());
655 self
656 }
657
658 #[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 #[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 #[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 pub fn get_retries(&self) -> Option<&u32> {
724 self.retries.as_ref()
725 }
726 pub fn set_retries(&mut self, v: u32) -> &mut Self {
733 self.retries = Some(v);
734 self
735 }
736 pub fn retries(mut self, v: u32) -> Self {
743 self.retries = Some(v);
744 self
745 }
746
747 #[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 #[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 #[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 pub fn get_user(&self) -> Option<&String> {
875 self.user.as_ref()
876 }
877 pub fn set_user(&mut self, v: impl Into<String>) -> &mut Self {
883 self.user = Some(v.into());
884 self
885 }
886 pub fn user(mut self, v: impl Into<String>) -> Self {
892 self.user = Some(v.into());
893 self
894 }
895
896 #[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 #[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 #[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 pub fn get_charset(&self) -> Option<&String> {
1054 self.charset.as_ref()
1055 }
1056 pub fn set_charset(&mut self, v: impl Into<String>) -> &mut Self {
1062 self.charset = Some(v.into());
1063 self
1064 }
1065 pub fn charset(mut self, v: impl Into<String>) -> Self {
1071 self.charset = Some(v.into());
1072 self
1073 }
1074
1075 pub fn get_command_charset(&self) -> Option<&String> {
1081 self.command_charset.as_ref()
1082 }
1083 pub fn set_command_charset(&mut self, v: impl Into<String>) -> &mut Self {
1089 self.command_charset = Some(v.into());
1090 self
1091 }
1092 pub fn command_charset(mut self, v: impl Into<String>) -> Self {
1098 self.command_charset = Some(v.into());
1099 self
1100 }
1101
1102 pub fn get_language(&self) -> Option<&String> {
1108 self.language.as_ref()
1109 }
1110 pub fn set_language(&mut self, v: impl Into<String>) -> &mut Self {
1116 self.language = Some(v.into());
1117 self
1118 }
1119 pub fn language(mut self, v: impl Into<String>) -> Self {
1125 self.language = Some(v.into());
1126 self
1127 }
1128
1129 #[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 #[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 #[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 #[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 #[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 #[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 #[cfg(all(feature = "lt2022_2", not(feature = "lt2021_2")))]
1337 pub fn get_debug(&self) -> bool {
1338 self.debug
1339 }
1340 #[cfg(not(feature = "lt2022_2"))]
1348 pub fn get_debug_variable(&self) -> Option<&[String]> {
1349 self.debug_variable.as_deref()
1350 }
1351 #[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 #[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 #[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 #[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 pub fn get_display_version(&self) -> bool {
1406 self.display_version
1407 }
1408 pub fn set_display_version(&mut self, v: bool) -> &mut Self {
1414 self.display_version = v;
1415 self
1416 }
1417 pub fn display_version(mut self, v: bool) -> Self {
1423 self.display_version = v;
1424 self
1425 }
1426
1427 pub fn get_display_help(&self) -> bool {
1433 self.display_help
1434 }
1435 pub fn set_display_help(&mut self, v: bool) -> &mut Self {
1441 self.display_help = v;
1442 self
1443 }
1444 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 #[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}