Skip to main content

perforce_cli/cmd/
dirs.rs

1use std::ffi::OsStr;
2use std::path::{Path, PathBuf};
3use std::process::{Child, Command, Stdio};
4
5use super::{ExclusiveOption, SubCommand, Unselected};
6
7use crate::global::GlobalOpts;
8use crate::spawn::ParameterizedSpawn;
9
10// ---------------------------------------------------------------------------
11// Workspace view form (-C -D -H -S stream -i --ignore-changeview)
12// ---------------------------------------------------------------------------
13
14/// The client-workspace-view form of `p4 dirs`.
15///
16/// Lists directories according to the current client view (`-C`), the client
17/// have list (`-H`), or a stream (`-S stream`), optionally ignoring the case
18/// of the directory argument (`-i`) and removing the changelist limit on
19/// depot paths (`--ignore-changeview`).
20#[derive(Debug, Clone, Default)]
21pub struct WorkspaceView {
22    client_mapped_only: bool,
23
24    client_have_list_only: bool,
25
26    #[cfg(not(feature = "lt2016_1"))]
27    case_insensitive: bool,
28
29    #[cfg(not(feature = "lt2025_2"))]
30    ignore_changeview: bool,
31
32    stream: Option<String>,
33}
34
35// ---------------------------------------------------------------------------
36// Stream view form (-D --streamviews)
37// ---------------------------------------------------------------------------
38
39/// The stream-components form of `p4 dirs`.
40///
41/// Reports files and directories from stream paths and components with
42/// `--streamviews`, where imported files are represented as symbolic links
43/// under the stream depot path.
44#[cfg(not(feature = "lt2022_2"))]
45#[derive(Debug, Clone, Default)]
46pub struct StreamView {}
47
48// ---------------------------------------------------------------------------
49// Mode dispatch
50// ---------------------------------------------------------------------------
51
52impl ExclusiveOption for WorkspaceView {
53    fn inject_args(&self, command: &mut Command) {
54        if self.client_mapped_only {
55            command.arg("-C");
56        }
57
58        if self.client_have_list_only {
59            command.arg("-H");
60        }
61
62        if let Some(stream) = &self.stream {
63            command.arg("-S").arg(stream);
64        }
65
66        #[cfg(not(feature = "lt2016_1"))]
67        if self.case_insensitive {
68            command.arg("-i");
69        }
70
71        #[cfg(not(feature = "lt2025_2"))]
72        if self.ignore_changeview {
73            command.arg("--ignore-changeview");
74        }
75    }
76}
77
78#[cfg(not(feature = "lt2022_2"))]
79impl ExclusiveOption for StreamView {
80    fn inject_args(&self, command: &mut Command) {
81        command.arg("--streamviews");
82    }
83}
84
85// ---------------------------------------------------------------------------
86// Entry
87// ---------------------------------------------------------------------------
88
89#[cfg_attr(
90    feature = "lt2016_1",
91    doc = "`p4 [g-opts] dirs [-C -D -H] [-S stream] depot_directory[revRange]...`"
92)]
93#[cfg_attr(
94    all(not(feature = "lt2016_1"), feature = "lt2017_2"),
95    doc = "`p4 [g-opts] dirs [-C -D -H] [-S stream] [-i] depot_directory[revRange]...`"
96)]
97#[cfg_attr(
98    all(not(feature = "lt2017_2"), feature = "lt2018_1"),
99    doc = "`p4 [g-opts] dirs [-C -D -H] [-S stream] [-i] depot_directory[revRange]...`",
100    doc = "",
101    doc = "`p4 [g-opts] dirs [-S stream] [-i] depot_directory[revRange]...`"
102)]
103#[cfg_attr(
104    all(not(feature = "lt2018_1"), feature = "lt2022_2"),
105    doc = "`p4 [g-opts] dirs [-C -D -H] [-S stream] [-i] depot_directories*[revSpec]`"
106)]
107#[cfg_attr(
108    all(not(feature = "lt2022_2"), feature = "lt2026_1"),
109    doc = "`p4 [g-opts] dirs [-C -D -H] [-S stream] [-i] depot_directories*[revSpec]`",
110    doc = "",
111    doc = "`p4 [g-opts] dirs [-D] [--streamviews] depot_directories*[revSpec]`"
112)]
113#[cfg_attr(
114    not(feature = "lt2026_1"),
115    doc = "`p4 [g-opts] dirs [-C -D -H] [-S stream] [-i] depot_directories*[revSpec]`",
116    doc = "",
117    doc = "`p4 [g-opts] dirs [-D] [--streamviews] depot_directories*[revSpec]`",
118    doc = "",
119    doc = "`p4 [g-opts] dirs [-D] [[-C] [-H] [-S stream] [-i] [--ignore-changeview] | [--streamviews]] depot_directories*[revSpec]`"
120)]
121///
122/// Lists the immediate subdirectories of the specified depot directories.
123///
124/// `p4 dirs` is meant to be used in scripts rather than from the command line.
125#[cfg_attr(
126    feature = "lt2018_1",
127    doc = "",
128    doc = "The `depot_directory` argument must be provided in depot or local syntax and must end with the `*` wildcard."
129)]
130#[cfg_attr(
131    all(not(feature = "lt2018_1"), feature = "lt2025_2"),
132    doc = "",
133    doc = "The `depot_directories` argument must be provided in depot or local syntax and must end with the `*` wildcard."
134)]
135#[cfg_attr(
136    not(feature = "lt2025_2"),
137    doc = "",
138    doc = "If you use streams, you must provide the `depot_directories` argument in depot syntax. Otherwise, you can use depot or local syntax. The argument must end with the `*` wildcard."
139)]
140///
141/// `p4 dirs` only lists the immediate subdirectories of the directory
142/// arguments.
143///
144/// By default, only subdirectories that contain at least one undeleted file
145/// are returned; [`Self::include_deleted`] (`-D`) also lists subdirectories
146/// that contain only deleted files.
147///
148#[cfg_attr(
149    feature = "lt2018_2",
150    doc = "If you include a revision specifier or revision range as part of a directory argument, then the only subdirectories returned are those that contain at least one file revision that matches the given specifier."
151)]
152#[cfg_attr(
153    not(feature = "lt2018_2"),
154    doc = "If you include a revision specifier or revision range as part of a directory argument, the only subdirectories returned are those that contain at least one file revision that matches the given specifier."
155)]
156///
157/// # Usage notes
158///
159#[cfg_attr(
160    feature = "lt2024_1",
161    doc = "Perforce does not track directories in its database. Therefore, the `...` wildcard is not supported."
162)]
163#[cfg_attr(
164    all(not(feature = "lt2024_1"), feature = "lt2024_2"),
165    doc = "Helix Core Server does not track directories in its database. Therefore, the `...` wildcard is not supported."
166)]
167#[cfg_attr(
168    not(feature = "lt2024_2"),
169    doc = "P4 Server does not track directories in its database. Therefore, the `...` wildcard is not supported."
170)]
171#[derive(Debug, Clone, Default)]
172pub struct Dirs<M = Unselected> {
173    bin: PathBuf,
174
175    global_opts: GlobalOpts,
176
177    include_deleted: bool,
178
179    mode: M,
180}
181
182impl Dirs<Unselected> {
183    /// Creates a new `p4 dirs` command.
184    ///
185    /// `bin` is the path to the Perforce command-line executable.
186    pub fn new(bin: impl Into<PathBuf>, global_opts: GlobalOpts) -> Self {
187        Self {
188            bin: bin.into(),
189            global_opts,
190            include_deleted: false,
191            mode: Unselected,
192        }
193    }
194
195    /// # Description
196    ///
197    /// -C
198    ///
199    /// Display only those directories that are mapped through the current
200    /// client view.
201    ///
202    /// Enters the [`WorkspaceView`] form with [`WorkspaceView`]'s
203    /// [`client_mapped_only`](Dirs::client_mapped_only) flag set.
204    pub fn client_mapped_only(self) -> Dirs<WorkspaceView> {
205        Dirs {
206            bin: self.bin,
207            global_opts: self.global_opts,
208            include_deleted: self.include_deleted,
209            mode: WorkspaceView {
210                client_mapped_only: true,
211                ..Default::default()
212            },
213        }
214    }
215
216    /// # Description
217    ///
218    /// -H
219    ///
220    /// Include only those directories that contain files on the current
221    /// client workspace's `p4 have` list.
222    ///
223    /// Enters the [`WorkspaceView`] form with [`WorkspaceView`]'s
224    /// [`client_have_list_only`](Dirs::client_have_list_only) flag set.
225    pub fn client_have_list_only(self) -> Dirs<WorkspaceView> {
226        Dirs {
227            bin: self.bin,
228            global_opts: self.global_opts,
229            include_deleted: self.include_deleted,
230            mode: WorkspaceView {
231                client_have_list_only: true,
232                ..Default::default()
233            },
234        }
235    }
236
237    /// # Description
238    ///
239    /// -S stream
240    ///
241    /// List directories mapped for the specified stream.
242    ///
243    /// Enters the [`WorkspaceView`] form with the stream selected.
244    pub fn stream(self, v: impl Into<String>) -> Dirs<WorkspaceView> {
245        Dirs {
246            bin: self.bin,
247            global_opts: self.global_opts,
248            include_deleted: self.include_deleted,
249            mode: WorkspaceView {
250                stream: Some(v.into()),
251                ..Default::default()
252            },
253        }
254    }
255
256    /// # Description
257    ///
258    /// -i
259    ///
260    /// Ignore the case of the directory argument when listing directories in
261    /// a case-sensitive server.
262    ///
263    /// Enters the [`WorkspaceView`] form with [`WorkspaceView`]'s
264    /// [`case_insensitive`](Dirs::case_insensitive) flag set.
265    #[cfg(not(feature = "lt2016_1"))]
266    pub fn case_insensitive(self) -> Dirs<WorkspaceView> {
267        Dirs {
268            bin: self.bin,
269            global_opts: self.global_opts,
270            include_deleted: self.include_deleted,
271            mode: WorkspaceView {
272                case_insensitive: true,
273                ..Default::default()
274            },
275        }
276    }
277
278    /// # Description
279    ///
280    /// `--ignore-changeview`
281    ///
282    /// Remove the changelist limit on depot paths. See ChangeView in
283    /// [`p4 client`](crate::cmd::Client).
284    ///
285    /// Enters the [`WorkspaceView`] form with [`WorkspaceView`]'s
286    /// [`ignore_changeview`](Dirs::ignore_changeview) flag set.
287    #[cfg(not(feature = "lt2025_2"))]
288    pub fn ignore_changeview(self) -> Dirs<WorkspaceView> {
289        Dirs {
290            bin: self.bin,
291            global_opts: self.global_opts,
292            include_deleted: self.include_deleted,
293            mode: WorkspaceView {
294                ignore_changeview: true,
295                ..Default::default()
296            },
297        }
298    }
299
300    /// # Description
301    ///
302    /// `--streamviews`
303    ///
304    /// Report files and directories from stream paths and components, where
305    /// imported files are represented as symbolic links under the stream
306    /// depot path.
307    ///
308    /// Enters the [`StreamView`] form.
309    #[cfg(not(feature = "lt2022_2"))]
310    pub fn stream_view(self) -> Dirs<StreamView> {
311        Dirs {
312            bin: self.bin,
313            global_opts: self.global_opts,
314            include_deleted: self.include_deleted,
315            mode: StreamView::default(),
316        }
317    }
318}
319
320impl Dirs<WorkspaceView> {
321    /// # Description
322    ///
323    /// -C
324    ///
325    /// Display only those directories that are mapped through the current
326    /// client view.
327    pub fn get_client_mapped_only(&self) -> bool {
328        self.mode.client_mapped_only
329    }
330
331    /// # Description
332    ///
333    /// -C
334    ///
335    /// Display only those directories that are mapped through the current
336    /// client view.
337    pub fn set_client_mapped_only(&mut self, v: bool) -> &mut Self {
338        self.mode.client_mapped_only = v;
339        self
340    }
341
342    /// # Description
343    ///
344    /// -C
345    ///
346    /// Display only those directories that are mapped through the current
347    /// client view.
348    pub fn client_mapped_only(mut self, v: bool) -> Self {
349        self.set_client_mapped_only(v);
350        self
351    }
352
353    /// # Description
354    ///
355    /// -H
356    ///
357    /// Include only those directories that contain files on the current
358    /// client workspace's `p4 have` list.
359    pub fn get_client_have_list_only(&self) -> bool {
360        self.mode.client_have_list_only
361    }
362
363    /// # Description
364    ///
365    /// -H
366    ///
367    /// Include only those directories that contain files on the current
368    /// client workspace's `p4 have` list.
369    pub fn set_client_have_list_only(&mut self, v: bool) -> &mut Self {
370        self.mode.client_have_list_only = v;
371        self
372    }
373
374    /// # Description
375    ///
376    /// -H
377    ///
378    /// Include only those directories that contain files on the current
379    /// client workspace's `p4 have` list.
380    pub fn client_have_list_only(mut self, v: bool) -> Self {
381        self.set_client_have_list_only(v);
382        self
383    }
384
385    /// # Description
386    ///
387    /// -S stream
388    ///
389    /// List directories mapped for the specified stream.
390    pub fn get_stream(&self) -> Option<&str> {
391        self.mode.stream.as_deref()
392    }
393
394    /// # Description
395    ///
396    /// -S stream
397    ///
398    /// List directories mapped for the specified stream.
399    pub fn set_stream(&mut self, v: impl Into<String>) -> &mut Self {
400        self.mode.stream = Some(v.into());
401        self
402    }
403
404    /// # Description
405    ///
406    /// -S stream
407    ///
408    /// List directories mapped for the specified stream.
409    pub fn stream(mut self, v: impl Into<String>) -> Self {
410        self.set_stream(v);
411        self
412    }
413
414    /// # Description
415    ///
416    /// -i
417    ///
418    /// Ignore the case of the directory argument when listing directories in
419    /// a case-sensitive server.
420    #[cfg(not(feature = "lt2016_1"))]
421    pub fn get_case_insensitive(&self) -> bool {
422        self.mode.case_insensitive
423    }
424
425    /// # Description
426    ///
427    /// -i
428    ///
429    /// Ignore the case of the directory argument when listing directories in
430    /// a case-sensitive server.
431    #[cfg(not(feature = "lt2016_1"))]
432    pub fn set_case_insensitive(&mut self, v: bool) -> &mut Self {
433        self.mode.case_insensitive = v;
434        self
435    }
436
437    /// # Description
438    ///
439    /// -i
440    ///
441    /// Ignore the case of the directory argument when listing directories in
442    /// a case-sensitive server.
443    #[cfg(not(feature = "lt2016_1"))]
444    pub fn case_insensitive(mut self, v: bool) -> Self {
445        self.set_case_insensitive(v);
446        self
447    }
448
449    /// # Description
450    ///
451    /// `--ignore-changeview`
452    ///
453    /// Remove the changelist limit on depot paths. See ChangeView in
454    /// [`p4 client`](crate::cmd::Client).
455    #[cfg(not(feature = "lt2025_2"))]
456    pub fn get_ignore_changeview(&self) -> bool {
457        self.mode.ignore_changeview
458    }
459
460    /// # Description
461    ///
462    /// `--ignore-changeview`
463    ///
464    /// Remove the changelist limit on depot paths. See ChangeView in
465    /// [`p4 client`](crate::cmd::Client).
466    #[cfg(not(feature = "lt2025_2"))]
467    pub fn set_ignore_changeview(&mut self, v: bool) -> &mut Self {
468        self.mode.ignore_changeview = v;
469        self
470    }
471
472    /// # Description
473    ///
474    /// `--ignore-changeview`
475    ///
476    /// Remove the changelist limit on depot paths. See ChangeView in
477    /// [`p4 client`](crate::cmd::Client).
478    #[cfg(not(feature = "lt2025_2"))]
479    pub fn ignore_changeview(mut self, v: bool) -> Self {
480        self.set_ignore_changeview(v);
481        self
482    }
483}
484
485impl<M: ExclusiveOption> Dirs<M> {
486    /// Get the Perforce command path.
487    pub fn get_bin(&self) -> &Path {
488        &self.bin
489    }
490
491    /// Set the Perforce command path.
492    pub fn set_bin(&mut self, bin: impl Into<PathBuf>) -> &mut Self {
493        self.bin = bin.into();
494        self
495    }
496
497    /// Set the Perforce command path.
498    pub fn bin(mut self, bin: impl Into<PathBuf>) -> Self {
499        self.set_bin(bin);
500        self
501    }
502
503    /// # Description
504    ///
505    /// g-opts
506    ///
507    #[cfg_attr(
508        feature = "lt2014_2",
509        doc = "See the [Global Options](GlobalOpts) section."
510    )]
511    #[cfg_attr(
512        all(feature = "lt2015_1", not(feature = "lt2014_2")),
513        doc = "See the [“Global Options”](GlobalOpts) section."
514    )]
515    #[cfg_attr(
516        all(feature = "lt2017_1", not(feature = "lt2015_1")),
517        doc = "See [“Global Options”](GlobalOpts)."
518    )]
519    #[cfg_attr(
520        all(feature = "lt2018_2", not(feature = "lt2017_1")),
521        doc = "See [Global Options](GlobalOpts)."
522    )]
523    #[cfg_attr(not(feature = "lt2018_2"), doc = "See [Global options](GlobalOpts).")]
524    pub fn get_global_opts(&self) -> &GlobalOpts {
525        &self.global_opts
526    }
527
528    /// # Description
529    ///
530    /// g-opts
531    ///
532    #[cfg_attr(
533        feature = "lt2014_2",
534        doc = "See the [Global Options](GlobalOpts) section."
535    )]
536    #[cfg_attr(
537        all(feature = "lt2015_1", not(feature = "lt2014_2")),
538        doc = "See the [“Global Options”](GlobalOpts) section."
539    )]
540    #[cfg_attr(
541        all(feature = "lt2017_1", not(feature = "lt2015_1")),
542        doc = "See [“Global Options”](GlobalOpts)."
543    )]
544    #[cfg_attr(
545        all(feature = "lt2018_2", not(feature = "lt2017_1")),
546        doc = "See [Global Options](GlobalOpts)."
547    )]
548    #[cfg_attr(not(feature = "lt2018_2"), doc = "See [Global options](GlobalOpts).")]
549    pub fn set_global_opts(&mut self, v: GlobalOpts) -> &mut Self {
550        self.global_opts = v;
551        self
552    }
553
554    /// # Description
555    ///
556    /// g-opts
557    ///
558    #[cfg_attr(
559        feature = "lt2014_2",
560        doc = "See the [Global Options](GlobalOpts) section."
561    )]
562    #[cfg_attr(
563        all(feature = "lt2015_1", not(feature = "lt2014_2")),
564        doc = "See the [“Global Options”](GlobalOpts) section."
565    )]
566    #[cfg_attr(
567        all(feature = "lt2017_1", not(feature = "lt2015_1")),
568        doc = "See [“Global Options”](GlobalOpts)."
569    )]
570    #[cfg_attr(
571        all(feature = "lt2018_2", not(feature = "lt2017_1")),
572        doc = "See [Global Options](GlobalOpts)."
573    )]
574    #[cfg_attr(not(feature = "lt2018_2"), doc = "See [Global options](GlobalOpts).")]
575    pub fn global_opts(mut self, v: GlobalOpts) -> Self {
576        self.set_global_opts(v);
577        self
578    }
579
580    /// # Description
581    ///
582    /// -D
583    ///
584    /// Include subdirectories that contain only deleted files. By default,
585    /// these directories are not displayed.
586    pub fn get_include_deleted(&self) -> bool {
587        self.include_deleted
588    }
589
590    /// # Description
591    ///
592    /// -D
593    ///
594    /// Include subdirectories that contain only deleted files. By default,
595    /// these directories are not displayed.
596    pub fn set_include_deleted(&mut self, v: bool) -> &mut Self {
597        self.include_deleted = v;
598        self
599    }
600
601    /// # Description
602    ///
603    /// -D
604    ///
605    /// Include subdirectories that contain only deleted files. By default,
606    /// these directories are not displayed.
607    pub fn include_deleted(mut self, v: bool) -> Self {
608        self.set_include_deleted(v);
609        self
610    }
611}
612
613impl<M: ExclusiveOption> SubCommand for Dirs<M> {
614    fn name(&self) -> &str {
615        "dirs"
616    }
617
618    fn inject_local_args(&self, command: &mut Command) {
619        if self.include_deleted {
620            command.arg("-D");
621        }
622
623        self.mode.inject_args(command);
624    }
625
626    fn global_opts(&self) -> Option<&GlobalOpts> {
627        Some(&self.global_opts)
628    }
629}
630
631impl<M: ExclusiveOption> ParameterizedSpawn<()> for Dirs<M> {
632    type Output = Child;
633    type Error = std::io::Error;
634
635    /// Spawns `p4 dirs` without directory arguments as a child process with
636    /// piped standard output and error streams.
637    fn spawn_with(&mut self, (): ()) -> Result<Self::Output, Self::Error> {
638        self.setup_command(&self.bin)
639            .stdout(Stdio::piped())
640            .stderr(Stdio::piped())
641            .spawn()
642    }
643}
644
645impl<M, S, I> ParameterizedSpawn<(S,)> for Dirs<M>
646where
647    M: ExclusiveOption,
648    S: IntoIterator<Item = I>,
649    I: AsRef<OsStr>,
650{
651    type Output = Child;
652    type Error = std::io::Error;
653
654    /// Spawns `p4 dirs` for the given depot directories as a child process
655    /// with piped standard output and error streams.
656    fn spawn_with(&mut self, (directories,): (S,)) -> Result<Self::Output, Self::Error> {
657        self.setup_command(&self.bin)
658            .args(directories)
659            .stdout(Stdio::piped())
660            .stderr(Stdio::piped())
661            .spawn()
662    }
663}
664
665#[cfg(test)]
666mod tests {
667    use super::*;
668    use crate::cmd::args_of;
669
670    fn args(cmd: &impl SubCommand) -> Vec<String> {
671        args_of(&cmd.setup_command("p4"))
672    }
673
674    #[test]
675    fn plain_form() {
676        let cmd = Dirs::new("p4", GlobalOpts::new());
677        assert_eq!(args(&cmd), ["dirs"]);
678    }
679
680    #[test]
681    fn include_deleted_is_shared_by_every_form() {
682        let cmd = Dirs::new("p4", GlobalOpts::new()).include_deleted(true);
683        assert_eq!(args(&cmd), ["dirs", "-D"]);
684
685        let cmd = Dirs::new("p4", GlobalOpts::new())
686            .client_mapped_only()
687            .include_deleted(true);
688        assert_eq!(args(&cmd), ["dirs", "-D", "-C"]);
689
690        #[cfg(not(feature = "lt2022_2"))]
691        {
692            let cmd = Dirs::new("p4", GlobalOpts::new())
693                .stream_view()
694                .include_deleted(true);
695            assert_eq!(args(&cmd), ["dirs", "-D", "--streamviews"]);
696        }
697    }
698
699    #[test]
700    fn workspace_view_arguments() {
701        let cmd = Dirs::new("p4", GlobalOpts::new())
702            .client_mapped_only()
703            .client_have_list_only(true)
704            .stream("main")
705            .include_deleted(true);
706
707        assert_eq!(args(&cmd), ["dirs", "-D", "-C", "-H", "-S", "main"]);
708    }
709
710    #[test]
711    fn stream_accessors() {
712        let mut cmd = Dirs::new("p4", GlobalOpts::new()).stream("release");
713        assert_eq!(cmd.get_stream(), Some("release"));
714
715        cmd.set_stream("main");
716        assert_eq!(cmd.get_stream(), Some("main"));
717        assert_eq!(args(&cmd), ["dirs", "-S", "main"]);
718    }
719
720    #[cfg(not(feature = "lt2016_1"))]
721    #[test]
722    fn case_insensitive_flag() {
723        let cmd = Dirs::new("p4", GlobalOpts::new()).case_insensitive();
724        assert_eq!(args(&cmd), ["dirs", "-i"]);
725
726        let mut cmd = Dirs::new("p4", GlobalOpts::new()).client_mapped_only();
727        assert!(!cmd.get_case_insensitive());
728
729        cmd.set_case_insensitive(true);
730        assert!(cmd.get_case_insensitive());
731        assert_eq!(args(&cmd), ["dirs", "-C", "-i"]);
732    }
733
734    #[cfg(not(feature = "lt2022_2"))]
735    #[test]
736    fn streamviews_flag() {
737        let cmd = Dirs::new("p4", GlobalOpts::new()).stream_view();
738        assert_eq!(args(&cmd), ["dirs", "--streamviews"]);
739    }
740
741    #[cfg(not(feature = "lt2025_2"))]
742    #[test]
743    fn ignore_changeview_flag() {
744        let cmd = Dirs::new("p4", GlobalOpts::new()).ignore_changeview();
745        assert_eq!(args(&cmd), ["dirs", "--ignore-changeview"]);
746
747        let mut cmd = Dirs::new("p4", GlobalOpts::new()).client_mapped_only();
748        assert!(!cmd.get_ignore_changeview());
749
750        cmd.set_ignore_changeview(true);
751        assert!(cmd.get_ignore_changeview());
752        assert_eq!(args(&cmd), ["dirs", "-C", "--ignore-changeview"]);
753    }
754
755    #[test]
756    fn global_opts_are_injected_once() {
757        let cmd = Dirs::new(
758            "p4",
759            GlobalOpts::new().port("localhost:1666").quiet_mode(true),
760        )
761        .stream("main");
762
763        assert_eq!(
764            args(&cmd),
765            ["-p", "localhost:1666", "-q", "dirs", "-S", "main"]
766        );
767    }
768}