perforce-cli 0.1.0-alpha.1

A type-safe builder library for spawning Perforce (p4) commands, with compile-time option state isolation and multi-version support.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
use std::{
    ffi::OsStr,
    path::PathBuf,
    process::{Child, Stdio},
};

use super::{ExclusiveOption, SubCommand, Unselected};

use crate::global::GlobalOpts;
use crate::spawn::ParameterizedSpawn;

/// `-l`: full text of each changelist description.
#[derive(Debug, Clone, Copy, Default)]
pub struct FullDescription;

impl ExclusiveOption for FullDescription {
    fn inject_args(&self, command: &mut std::process::Command) {
        command.arg("-l");
    }
}

/// `-L`: full text truncated at 250 characters.
#[derive(Debug, Clone, Copy, Default)]
pub struct TruncatedDescription;

impl ExclusiveOption for TruncatedDescription {
    fn inject_args(&self, command: &mut std::process::Command) {
        command.arg("-L");
    }
}

/// User filter for the `-u` / `--me` options.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum User {
    /// List only changes made from the named user (`-u user`).
    User(String),
    /// Equivalent to `-u $P4USER` (`--me`).
    #[cfg(not(feature = "lt2016_1"))]
    Me,
}

/// Status of a changelist as accepted by the `-s` option.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Status {
    /// Pending changelists.
    Pending,
    /// Submitted changelists.
    Submitted,
    /// Shelved changelists.
    Shelved,
}

impl Status {
    /// Returns the command-line representation of this status.
    pub fn as_str(&self) -> &'static str {
        match self {
            Status::Pending => "pending",
            Status::Submitted => "submitted",
            Status::Shelved => "shelved",
        }
    }
}

#[cfg_attr(
    feature = "lt2015_2",
    doc = "`p4 [g-opts] changes [-i -t -l -L -f] [-c client] [-m max] [-s status] [-u user] [file[RevRange] ...]`"
)]
#[cfg_attr(
    all(feature = "lt2016_1", not(feature = "lt2015_2")),
    doc = "`p4 [g-opts] changes [-i -t -l -L -f] [-c client] [ -e changelist#][-m max] [-s status] [-u user][file[RevRange] ...]`"
)]
#[cfg_attr(
    all(feature = "lt2017_2", not(feature = "lt2016_1")),
    doc = "`p4 [g-opts] changes [-i -t -l -L -f] [-c client] [ -e changelist#][-m max] [-s status] [-u user | --me][file[RevRange] ...]`"
)]
#[cfg_attr(
    all(feature = "lt2022_2", not(feature = "lt2017_2")),
    doc = "`p4 [g-opts] changes [-i -t -l -L -f] [-c client] [ -e changelist#][-m max] [-r] [-s status] [-u user | --me] [file[RevRange] ...]`"
)]
#[cfg_attr(
    not(feature = "lt2022_2"),
    doc = "`p4 [g-opts] changes [-i -t -l -L -f] [-c client] [ -e changelist#][-m max] [-r] [-s status] [-u user | --me] [file[RevRange] ...] [--stream | --nostream]`"
)]
///
/// List submitted and pending changelists.
///
/// The command `p4 changelists` is an alias for `p4 changes`.
///
/// The `L` type parameter tracks the `-l` / `-L` long output mode at
/// compile time; see [`FullDescription`], [`TruncatedDescription`],
/// [`Self::long_output_full`], and [`Self::long_output_truncated`].
#[derive(Debug, Clone, Default)]
pub struct Changes<L = Unselected> {
    bin: PathBuf,

    global_opts: GlobalOpts,

    #[cfg(not(feature = "lt2015_2"))]
    min_change_list: Option<String>,

    include_restricted: bool,

    include_integrated: bool,

    include_time: bool,

    long_output: L,

    limit: Option<u64>,

    #[cfg(not(feature = "lt2017_2"))]
    reverse_order: bool,

    filter_status: Option<Status>,

    filter_users: Option<Vec<User>>,

    filter_clients: Option<Vec<String>>,

    #[cfg(not(feature = "lt2025_1"))]
    client_case_insensitive: bool,

    #[cfg(not(feature = "lt2022_2"))]
    stream: Option<bool>,
}

impl Changes<Unselected> {
    /// Creates a new `p4 changes` command.
    ///
    /// `bin` is the path to the Perforce command-line executable.
    pub fn new(bin: impl Into<PathBuf>, global_opts: GlobalOpts) -> Self {
        Self {
            bin: bin.into(),
            global_opts,
            ..Self::default()
        }
    }

    /// # Description
    ///
    /// `-l`
    ///
    /// List long output, with the full text of each changelist description.
    ///
    /// Transitions this command to the [`FullDescription`] state.
    pub fn long_output_full(self) -> Changes<FullDescription> {
        Changes {
            bin: self.bin,
            global_opts: self.global_opts,
            #[cfg(not(feature = "lt2015_2"))]
            min_change_list: self.min_change_list,
            include_restricted: self.include_restricted,
            include_integrated: self.include_integrated,
            include_time: self.include_time,
            long_output: FullDescription,
            limit: self.limit,
            #[cfg(not(feature = "lt2017_2"))]
            reverse_order: self.reverse_order,
            filter_status: self.filter_status,
            filter_users: self.filter_users,
            filter_clients: self.filter_clients,
            #[cfg(not(feature = "lt2025_1"))]
            client_case_insensitive: self.client_case_insensitive,
            #[cfg(not(feature = "lt2022_2"))]
            stream: self.stream,
        }
    }

    /// # Description
    ///
    /// `-L`
    ///
    /// List long output, with the full text of each changelist description
    /// truncated at 250 characters.
    ///
    /// Transitions this command to the [`TruncatedDescription`] state.
    pub fn long_output_truncated(self) -> Changes<TruncatedDescription> {
        Changes {
            bin: self.bin,
            global_opts: self.global_opts,
            #[cfg(not(feature = "lt2015_2"))]
            min_change_list: self.min_change_list,
            include_restricted: self.include_restricted,
            include_integrated: self.include_integrated,
            include_time: self.include_time,
            long_output: TruncatedDescription,
            limit: self.limit,
            #[cfg(not(feature = "lt2017_2"))]
            reverse_order: self.reverse_order,
            filter_status: self.filter_status,
            filter_users: self.filter_users,
            filter_clients: self.filter_clients,
            #[cfg(not(feature = "lt2025_1"))]
            client_case_insensitive: self.client_case_insensitive,
            #[cfg(not(feature = "lt2022_2"))]
            stream: self.stream,
        }
    }
}

impl<L: ExclusiveOption> ParameterizedSpawn for Changes<L> {
    type Input<'a> = &'a [&'a OsStr];
    type Output<'a> = Child;
    type Error = std::io::Error;

    /// Spawns `p4 changes` for the given files as a child process with piped
    /// standard output and error streams; use the returned [`Child`] handle
    /// to wait for it or interact with it.
    ///
    /// If files are specified, only changelists that affect those files are
    /// listed. Pass an empty slice to list all changelists.
    fn spawn_with<'a>(&mut self, files: Self::Input<'a>) -> Result<Self::Output<'a>, Self::Error> {
        self.setup_command(&self.bin)
            .args(files)
            .stdout(Stdio::piped())
            .stderr(Stdio::piped())
            .spawn()
    }
}

impl<L: ExclusiveOption> Changes<L> {
    /// # Description
    ///
    /// g-opts
    ///
    #[cfg_attr(
        feature = "lt2014_2",
        doc = "See the [Global Options](GlobalOpts) section."
    )]
    #[cfg_attr(
        all(feature = "lt2015_1", not(feature = "lt2014_2")),
        doc = "See the [“Global Options”](GlobalOpts) section."
    )]
    #[cfg_attr(
        all(feature = "lt2017_1", not(feature = "lt2015_1")),
        doc = "See [“Global Options”](GlobalOpts)."
    )]
    #[cfg_attr(
        all(feature = "lt2018_2", not(feature = "lt2017_1")),
        doc = "See [Global Options](GlobalOpts)."
    )]
    #[cfg_attr(not(feature = "lt2018_2"), doc = "See [Global options](GlobalOpts).")]
    pub fn get_global_opts(&self) -> &GlobalOpts {
        &self.global_opts
    }

    /// # Description
    ///
    /// g-opts
    ///
    #[cfg_attr(
        feature = "lt2014_2",
        doc = "See the [Global Options](GlobalOpts) section."
    )]
    #[cfg_attr(
        all(feature = "lt2015_1", not(feature = "lt2014_2")),
        doc = "See the [“Global Options”](GlobalOpts) section."
    )]
    #[cfg_attr(
        all(feature = "lt2017_1", not(feature = "lt2015_1")),
        doc = "See [“Global Options”](GlobalOpts)."
    )]
    #[cfg_attr(
        all(feature = "lt2018_2", not(feature = "lt2017_1")),
        doc = "See [Global Options](GlobalOpts)."
    )]
    #[cfg_attr(not(feature = "lt2018_2"), doc = "See [Global options](GlobalOpts).")]
    pub fn set_global_opts(&mut self, v: GlobalOpts) -> &mut Self {
        self.global_opts = v;
        self
    }

    /// # Description
    ///
    /// g-opts
    ///
    #[cfg_attr(
        feature = "lt2014_2",
        doc = "See the [Global Options](GlobalOpts) section."
    )]
    #[cfg_attr(
        all(feature = "lt2015_1", not(feature = "lt2014_2")),
        doc = "See the [“Global Options”](GlobalOpts) section."
    )]
    #[cfg_attr(
        all(feature = "lt2017_1", not(feature = "lt2015_1")),
        doc = "See [“Global Options”](GlobalOpts)."
    )]
    #[cfg_attr(
        all(feature = "lt2018_2", not(feature = "lt2017_1")),
        doc = "See [Global Options](GlobalOpts)."
    )]
    #[cfg_attr(not(feature = "lt2018_2"), doc = "See [Global options](GlobalOpts).")]
    pub fn global_opts(mut self, v: GlobalOpts) -> Self {
        self.global_opts = v;
        self
    }

    /// # Description
    ///
    /// `-c client`
    ///
    /// List only changes made from the named client workspace. This option
    /// can be repeated to filter for multiple clients.
    pub fn get_filter_clients(&self) -> Option<&[String]> {
        self.filter_clients.as_deref()
    }

    /// # Description
    ///
    /// `-c client`
    ///
    /// List only changes made from the named client workspace. This option
    /// can be repeated to filter for multiple clients.
    pub fn set_filter_client(&mut self, v: impl Into<String>) -> &mut Self {
        self.filter_clients
            .get_or_insert_with(Vec::new)
            .push(v.into());
        self
    }

    /// # Description
    ///
    /// `-c client`
    ///
    /// List only changes made from the named client workspace. This option
    /// can be repeated to filter for multiple clients.
    pub fn filter_client(mut self, v: impl Into<String>) -> Self {
        self.filter_clients
            .get_or_insert_with(Vec::new)
            .push(v.into());
        self
    }

    /// # Description
    ///
    /// `-e changelist#`
    ///
    /// Display only changes where the changelist number is equal to, or
    /// higher than, the specified changelist number.
    #[cfg(not(feature = "lt2015_2"))]
    pub fn get_min_change_list(&self) -> Option<&String> {
        self.min_change_list.as_ref()
    }

    /// # Description
    ///
    /// `-e changelist#`
    ///
    /// Display only changes where the changelist number is equal to, or
    /// higher than, the specified changelist number.
    #[cfg(not(feature = "lt2015_2"))]
    pub fn set_min_change_list(&mut self, v: impl Into<String>) -> &mut Self {
        self.min_change_list = Some(v.into());
        self
    }

    /// # Description
    ///
    /// `-e changelist#`
    ///
    /// Display only changes where the changelist number is equal to, or
    /// higher than, the specified changelist number.
    #[cfg(not(feature = "lt2015_2"))]
    pub fn min_change_list(mut self, v: impl Into<String>) -> Self {
        self.min_change_list = Some(v.into());
        self
    }

    /// # Description
    ///
    /// `-f`
    ///
    /// View restricted changes (requires admin permission).
    pub fn get_include_restricted(&self) -> bool {
        self.include_restricted
    }

    /// # Description
    ///
    /// `-f`
    ///
    /// View restricted changes (requires admin permission).
    pub fn set_include_restricted(&mut self, v: bool) -> &mut Self {
        self.include_restricted = v;
        self
    }

    /// # Description
    ///
    /// `-f`
    ///
    /// View restricted changes (requires admin permission).
    pub fn include_restricted(mut self, v: bool) -> Self {
        self.include_restricted = v;
        self
    }

    /// # Description
    ///
    /// `-i`
    ///
    /// Include changelists that affected files that were integrated with the
    /// specified files.
    pub fn get_include_integrated(&self) -> bool {
        self.include_integrated
    }

    /// # Description
    ///
    /// `-i`
    ///
    /// Include changelists that affected files that were integrated with the
    /// specified files.
    pub fn set_include_integrated(&mut self, v: bool) -> &mut Self {
        self.include_integrated = v;
        self
    }

    /// # Description
    ///
    /// `-i`
    ///
    /// Include changelists that affected files that were integrated with the
    /// specified files.
    pub fn include_integrated(mut self, v: bool) -> Self {
        self.include_integrated = v;
        self
    }

    /// # Description
    ///
    /// `-m max`
    ///
    /// List only the highest numbered `max` changes.
    pub fn get_limit(&self) -> Option<u64> {
        self.limit
    }

    /// # Description
    ///
    /// `-m max`
    ///
    /// List only the highest numbered `max` changes.
    pub fn set_limit(&mut self, v: u64) -> &mut Self {
        self.limit = Some(v);
        self
    }

    /// # Description
    ///
    /// `-m max`
    ///
    /// List only the highest numbered `max` changes.
    pub fn limit(mut self, v: u64) -> Self {
        self.limit = Some(v);
        self
    }

    /// # Description
    ///
    /// `-r`
    ///
    /// Reverse the order of the list, earliest first instead of most recent
    /// first.
    #[cfg(not(feature = "lt2017_2"))]
    pub fn get_reverse_order(&self) -> bool {
        self.reverse_order
    }

    /// # Description
    ///
    /// `-r`
    ///
    /// Reverse the order of the list, earliest first instead of most recent
    /// first.
    #[cfg(not(feature = "lt2017_2"))]
    pub fn set_reverse_order(&mut self, v: bool) -> &mut Self {
        self.reverse_order = v;
        self
    }

    /// # Description
    ///
    /// `-r`
    ///
    /// Reverse the order of the list, earliest first instead of most recent
    /// first.
    #[cfg(not(feature = "lt2017_2"))]
    pub fn reverse_order(mut self, v: bool) -> Self {
        self.reverse_order = v;
        self
    }

    /// # Description
    ///
    /// `-s status`
    ///
    /// Limit the list to the changelists with the specified status:
    /// `pending`, `submitted`, or `shelved`.
    pub fn get_status(&self) -> Option<Status> {
        self.filter_status
    }

    /// # Description
    ///
    /// `-s status`
    ///
    /// Limit the list to the changelists with the specified status:
    /// `pending`, `submitted`, or `shelved`.
    pub fn set_status(&mut self, v: Status) -> &mut Self {
        self.filter_status = Some(v);
        self
    }

    /// # Description
    ///
    /// `-s status`
    ///
    /// Limit the list to the changelists with the specified status:
    /// `pending`, `submitted`, or `shelved`.
    pub fn status(mut self, v: Status) -> Self {
        self.filter_status = Some(v);
        self
    }

    /// # Description
    ///
    /// `-t`
    ///
    /// Display the time as well as the date of each change.
    pub fn get_include_time(&self) -> bool {
        self.include_time
    }

    /// # Description
    ///
    /// `-t`
    ///
    /// Display the time as well as the date of each change.
    pub fn set_include_time(&mut self, v: bool) -> &mut Self {
        self.include_time = v;
        self
    }

    /// # Description
    ///
    /// `-t`
    ///
    /// Display the time as well as the date of each change.
    pub fn include_time(mut self, v: bool) -> Self {
        self.include_time = v;
        self
    }

    /// # Description
    ///
    /// `-u user` / `--me`
    ///
    /// List only changes made from the named user, or, with
    /// [`User::Me`], the current user (equivalent to `-u $P4USER`).
    /// This option can be repeated to filter for multiple users.
    pub fn get_filter_users(&self) -> Option<&[User]> {
        self.filter_users.as_deref()
    }

    /// # Description
    ///
    /// `-u user`
    ///
    /// List only changes made from the named user. This option can be
    /// repeated to filter for multiple users.
    pub fn set_filter_user(&mut self, v: impl Into<String>) -> &mut Self {
        self.filter_users
            .get_or_insert_with(Vec::new)
            .push(User::User(v.into()));
        self
    }

    /// # Description
    ///
    /// `-u user`
    ///
    /// List only changes made from the named user. This option can be
    /// repeated to filter for multiple users.
    pub fn filter_user(mut self, v: impl Into<String>) -> Self {
        self.filter_users
            .get_or_insert_with(Vec::new)
            .push(User::User(v.into()));
        self
    }

    /// # Description
    ///
    /// `--me`
    ///
    /// Equivalent to `-u $P4USER`.
    #[cfg(not(feature = "lt2016_1"))]
    pub fn set_filter_me(&mut self) -> &mut Self {
        self.filter_users
            .get_or_insert_with(Vec::new)
            .push(User::Me);
        self
    }

    /// # Description
    ///
    /// `--me`
    ///
    /// Equivalent to `-u $P4USER`.
    #[cfg(not(feature = "lt2016_1"))]
    pub fn filter_me(mut self) -> Self {
        self.filter_users
            .get_or_insert_with(Vec::new)
            .push(User::Me);
        self
    }

    /// # Description
    ///
    /// `--client-case-insensitive`
    ///
    /// Makes the `-c client` search pattern case-insensitive, even on a
    /// case-sensitive server.
    #[cfg(not(feature = "lt2025_1"))]
    pub fn get_client_case_insensitive(&self) -> bool {
        self.client_case_insensitive
    }

    /// # Description
    ///
    /// `--client-case-insensitive`
    ///
    /// Makes the `-c client` search pattern case-insensitive, even on a
    /// case-sensitive server.
    #[cfg(not(feature = "lt2025_1"))]
    pub fn set_client_case_insensitive(&mut self, v: bool) -> &mut Self {
        self.client_case_insensitive = v;
        self
    }

    /// # Description
    ///
    /// `--client-case-insensitive`
    ///
    /// Makes the `-c client` search pattern case-insensitive, even on a
    /// case-sensitive server.
    #[cfg(not(feature = "lt2025_1"))]
    pub fn client_case_insensitive(mut self, v: bool) -> Self {
        self.client_case_insensitive = v;
        self
    }

    /// # Description
    ///
    /// `--stream` / `--nostream`
    ///
    /// With `true`, display only changes that contain a stream spec
    /// (`--stream`). With `false`, display only changes that do not
    /// contain a stream spec (`--nostream`).
    #[cfg(not(feature = "lt2022_2"))]
    pub fn get_stream(&self) -> Option<bool> {
        self.stream
    }

    /// # Description
    ///
    /// `--stream` / `--nostream`
    ///
    /// With `true`, display only changes that contain a stream spec
    /// (`--stream`). With `false`, display only changes that do not
    /// contain a stream spec (`--nostream`).
    #[cfg(not(feature = "lt2022_2"))]
    pub fn set_stream(&mut self, v: bool) -> &mut Self {
        self.stream = Some(v);
        self
    }

    /// # Description
    ///
    /// `--stream` / `--nostream`
    ///
    /// With `true`, display only changes that contain a stream spec
    /// (`--stream`). With `false`, display only changes that do not
    /// contain a stream spec (`--nostream`).
    #[cfg(not(feature = "lt2022_2"))]
    pub fn stream(mut self, v: bool) -> Self {
        self.stream = Some(v);
        self
    }
}

impl<L: ExclusiveOption> SubCommand for Changes<L> {
    fn name(&self) -> &str {
        "changes"
    }

    fn inject_local_args(&self, command: &mut std::process::Command) {
        if let Some(ref clients) = self.filter_clients {
            for client in clients {
                command.arg("-c").arg(client);
            }
        }
        #[cfg(not(feature = "lt2025_1"))]
        if self.client_case_insensitive {
            command.arg("--client-case-insensitive");
        }
        #[cfg(not(feature = "lt2015_2"))]
        if let Some(ref min_change) = self.min_change_list {
            command.arg("-e").arg(min_change);
        }
        if self.include_restricted {
            command.arg("-f");
        }
        if self.include_integrated {
            command.arg("-i");
        }
        self.long_output.inject_args(command);
        if let Some(max) = self.limit {
            command.arg("-m").arg(max.to_string());
        }
        #[cfg(not(feature = "lt2017_2"))]
        if self.reverse_order {
            command.arg("-r");
        }
        if let Some(status) = self.filter_status {
            command.arg("-s").arg(status.as_str());
        }
        if self.include_time {
            command.arg("-t");
        }
        if let Some(ref users) = self.filter_users {
            for user in users {
                match user {
                    User::User(name) => {
                        command.arg("-u").arg(name);
                    }
                    #[cfg(not(feature = "lt2016_1"))]
                    User::Me => {
                        command.arg("--me");
                    }
                }
            }
        }
        #[cfg(not(feature = "lt2022_2"))]
        if let Some(stream) = self.stream {
            if stream {
                command.arg("--stream");
            } else {
                command.arg("--nostream");
            }
        }
    }

    fn global_opts(&self) -> Option<&GlobalOpts> {
        Some(&self.global_opts)
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::cmd::args_of;

    #[test]
    fn without_options() {
        let changes = Changes::new("p4", GlobalOpts::default());
        let cmd = changes.setup_command("p4");
        assert_eq!(args_of(&cmd), vec!["changes"]);
    }

    #[test]
    fn with_files() {
        let changes = Changes::new("p4", GlobalOpts::default());
        let mut cmd = changes.setup_command("p4");
        cmd.arg("//depot/project/...");
        assert_eq!(args_of(&cmd), vec!["changes", "//depot/project/..."]);
    }

    #[test]
    fn client() {
        let changes = Changes::new("p4", GlobalOpts::default()).filter_client("eds_elm");
        let cmd = changes.setup_command("p4");
        assert_eq!(args_of(&cmd), vec!["changes", "-c", "eds_elm"]);
    }

    #[test]
    fn multiple_clients() {
        let changes = Changes::new("p4", GlobalOpts::default())
            .filter_client("eds_elm")
            .filter_client("build_ws");
        let cmd = changes.setup_command("p4");
        assert_eq!(
            args_of(&cmd),
            vec!["changes", "-c", "eds_elm", "-c", "build_ws"]
        );
    }

    #[cfg(not(feature = "lt2015_2"))]
    #[test]
    fn min_change_list() {
        let changes = Changes::new("p4", GlobalOpts::default()).min_change_list("800");
        let cmd = changes.setup_command("p4");
        assert_eq!(args_of(&cmd), vec!["changes", "-e", "800"]);
    }

    #[test]
    fn include_restricted() {
        let changes = Changes::new("p4", GlobalOpts::default()).include_restricted(true);
        let cmd = changes.setup_command("p4");
        assert_eq!(args_of(&cmd), vec!["changes", "-f"]);
    }

    #[test]
    fn include_integrated() {
        let changes = Changes::new("p4", GlobalOpts::default()).include_integrated(true);
        let cmd = changes.setup_command("p4");
        assert_eq!(args_of(&cmd), vec!["changes", "-i"]);
    }

    #[test]
    fn long_output_full() {
        let changes = Changes::new("p4", GlobalOpts::default()).long_output_full();
        let cmd = changes.setup_command("p4");
        assert_eq!(args_of(&cmd), vec!["changes", "-l"]);
    }

    #[test]
    fn long_output_truncated() {
        let changes = Changes::new("p4", GlobalOpts::default()).long_output_truncated();
        let cmd = changes.setup_command("p4");
        assert_eq!(args_of(&cmd), vec!["changes", "-L"]);
    }

    #[test]
    fn limit() {
        let changes = Changes::new("p4", GlobalOpts::default()).limit(5);
        let cmd = changes.setup_command("p4");
        assert_eq!(args_of(&cmd), vec!["changes", "-m", "5"]);
    }

    #[cfg(not(feature = "lt2017_2"))]
    #[test]
    fn reverse_order() {
        let changes = Changes::new("p4", GlobalOpts::default()).reverse_order(true);
        let cmd = changes.setup_command("p4");
        assert_eq!(args_of(&cmd), vec!["changes", "-r"]);
    }

    #[test]
    fn status_pending() {
        let changes = Changes::new("p4", GlobalOpts::default()).status(Status::Pending);
        let cmd = changes.setup_command("p4");
        assert_eq!(args_of(&cmd), vec!["changes", "-s", "pending"]);
    }

    #[test]
    fn status_submitted() {
        let changes = Changes::new("p4", GlobalOpts::default()).status(Status::Submitted);
        let cmd = changes.setup_command("p4");
        assert_eq!(args_of(&cmd), vec!["changes", "-s", "submitted"]);
    }

    #[test]
    fn status_shelved() {
        let changes = Changes::new("p4", GlobalOpts::default()).status(Status::Shelved);
        let cmd = changes.setup_command("p4");
        assert_eq!(args_of(&cmd), vec!["changes", "-s", "shelved"]);
    }

    #[test]
    fn include_time() {
        let changes = Changes::new("p4", GlobalOpts::default()).include_time(true);
        let cmd = changes.setup_command("p4");
        assert_eq!(args_of(&cmd), vec!["changes", "-t"]);
    }

    #[test]
    fn user_name() {
        let changes = Changes::new("p4", GlobalOpts::default()).filter_user("edk");
        let cmd = changes.setup_command("p4");
        assert_eq!(args_of(&cmd), vec!["changes", "-u", "edk"]);
    }

    #[test]
    fn multiple_users() {
        let changes = Changes::new("p4", GlobalOpts::default())
            .filter_user("maria")
            .filter_user("edk");
        let cmd = changes.setup_command("p4");
        assert_eq!(args_of(&cmd), vec!["changes", "-u", "maria", "-u", "edk"]);
    }

    #[cfg(not(feature = "lt2016_1"))]
    #[test]
    fn user_me() {
        let changes = Changes::new("p4", GlobalOpts::default()).filter_me();
        let cmd = changes.setup_command("p4");
        assert_eq!(args_of(&cmd), vec!["changes", "--me"]);
    }

    #[cfg(not(feature = "lt2016_1"))]
    #[test]
    fn multiple_users_with_me() {
        let changes = Changes::new("p4", GlobalOpts::default())
            .filter_user("maria")
            .filter_me();
        let cmd = changes.setup_command("p4");
        assert_eq!(args_of(&cmd), vec!["changes", "-u", "maria", "--me"]);
    }

    #[cfg(not(feature = "lt2025_1"))]
    #[test]
    fn client_case_insensitive() {
        let changes = Changes::new("p4", GlobalOpts::default())
            .filter_client("eds_elm")
            .client_case_insensitive(true);
        let cmd = changes.setup_command("p4");
        assert_eq!(
            args_of(&cmd),
            vec!["changes", "-c", "eds_elm", "--client-case-insensitive"]
        );
    }

    #[cfg(not(feature = "lt2022_2"))]
    #[test]
    fn stream_spec() {
        let changes = Changes::new("p4", GlobalOpts::default()).stream(true);
        let cmd = changes.setup_command("p4");
        assert_eq!(args_of(&cmd), vec!["changes", "--stream"]);
    }

    #[cfg(not(feature = "lt2022_2"))]
    #[test]
    fn no_stream_spec() {
        let changes = Changes::new("p4", GlobalOpts::default()).stream(false);
        let cmd = changes.setup_command("p4");
        assert_eq!(args_of(&cmd), vec!["changes", "--nostream"]);
    }

    #[test]
    fn all_options_order() {
        let changes = Changes::new("p4", GlobalOpts::default())
            .filter_client("eds_elm")
            .include_restricted(true)
            .include_integrated(true)
            .long_output_full()
            .limit(5)
            .status(Status::Submitted)
            .include_time(true)
            .filter_user("edk");
        #[cfg(not(feature = "lt2015_2"))]
        let changes = changes.min_change_list("800");
        #[cfg(not(feature = "lt2017_2"))]
        let changes = changes.reverse_order(true);
        #[cfg(not(feature = "lt2022_2"))]
        let changes = changes.stream(true);
        let cmd = changes.setup_command("p4");
        let mut expected = vec!["changes", "-c", "eds_elm"];
        #[cfg(not(feature = "lt2015_2"))]
        expected.extend(["-e", "800"]);
        expected.extend(["-f", "-i", "-l", "-m", "5"]);
        #[cfg(not(feature = "lt2017_2"))]
        expected.push("-r");
        expected.extend(["-s", "submitted", "-t", "-u", "edk"]);
        #[cfg(not(feature = "lt2022_2"))]
        expected.push("--stream");
        assert_eq!(args_of(&cmd), expected);
    }

    #[test]
    fn long_output_full_preserves_other_options() {
        let changes = Changes::new("p4", GlobalOpts::default())
            .include_restricted(true)
            .include_time(true)
            .long_output_full();
        let cmd = changes.setup_command("p4");
        assert_eq!(args_of(&cmd), vec!["changes", "-f", "-l", "-t"]);
    }
}