pub struct DiffOptionsBuilder<M> { /* private fields */ }Expand description
Builder for DiffOptions, shared by commands such as p4 diff,
p4 diff2, p4 describe, and p4 annotate.
The mode type parameter tracks at compile time which kind of options are
being assembled. The format constructors (DiffOptionsBuilder::context,
DiffOptionsBuilder::rcs, DiffOptionsBuilder::summary,
DiffOptionsBuilder::unified, and DiffOptionsBuilder::new) produce
the DiffOptionsTypedMode state, where the whitespace builders
(DiffOptionsBuilder::ignore_line_endings,
DiffOptionsBuilder::ignore_changes_within_whitespace,
DiffOptionsBuilder::ignore_all_whitespace) become available;
DiffOptionsBuilder::raw produces the DiffOptionsRawMode state,
which offers no further options — the two states never mix.
Both states convert into DiffOptions via From, so command methods
that accept impl Into<DiffOptions> take a builder directly.
§Examples
use perforce_cli::cmd::DiffOptionsBuilder;
// `-dub`: unified format, ignore changes within whitespace
let builder =
DiffOptionsBuilder::unified(None).ignore_changes_within_whitespace();
// `-dc3`: context format with 3 lines of context
let builder = DiffOptionsBuilder::context(Some(3));
// `-d-C 25`: pass `-C 25` straight to an external diff program
let builder = DiffOptionsBuilder::raw("-C 25");Implementations§
Source§impl DiffOptionsBuilder<DiffOptionsTypedMode>
impl DiffOptionsBuilder<DiffOptionsTypedMode>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new builder in the DiffOptionsTypedMode state with the
default format and no whitespace handling; the resulting
DiffOptions emits no -d flag.
Sourcepub fn context(num: Option<u32>) -> Self
pub fn context(num: Option<u32>) -> Self
-dc[num]: context output format with num lines of context.
Sourcepub fn unified(num: Option<u32>) -> Self
pub fn unified(num: Option<u32>) -> Self
-du[num]: unified output format with num lines of context.
Examples found in repository?
27fn main() -> std::io::Result<()> {
28 let p4 = P4Cli::default();
29
30 // Workspace mode: force a diff against head, use the unified format with
31 // whitespace-insensitive comparison, and limit output to the first 10
32 // files. `force(true)` transitions the command into `WorkspaceMode`, and
33 // `limit(10)` further transitions it into `WorkspaceRegularMode` (where
34 // `-soptions` is unavailable).
35 let mut diff = p4
36 .diff()
37 .force(true)
38 .diff_options(DiffOptionsBuilder::unified(None).ignore_all_whitespace())
39 .limit(10);
40
41 let files = [OsStr::new("//depot/project/src/...")];
42 let output = diff.output_with(&files)?;
43 println!("{}", String::from_utf8_lossy(&output.stdout));
44
45 // Display mode: instead of full diffs, list only the unopened files that
46 // differ from the depot. `display_options` transitions `WorkspaceMode`
47 // into `WorkspaceDisplayMode`, where `-m max` is unavailable.
48 let mut list_changed = p4
49 .diff()
50 .force(true)
51 .display_options(DisplayOptions::UnopenedChanged);
52
53 let output = list_changed.output_with(&files)?;
54 println!("{}", String::from_utf8_lossy(&output.stdout));
55
56 // Stream-spec mode: diff a privately edited stream spec against the head
57 // version of another stream. `stream_spec_mode` transitions the command
58 // into `StreamSpecMode`; the stream spec is passed to `spawn_with`.
59 let mut stream_diff = p4.diff().stream_spec_mode();
60 let mut child = stream_diff.spawn_with(Some("//streams/main@head"))?;
61 child.wait()?;
62
63 Ok(())
64}Sourcepub fn ignore_line_endings(self) -> Self
pub fn ignore_line_endings(self) -> Self
-dl: ignore line-ending (CR/LF) convention when finding diffs.
Sourcepub fn ignore_changes_within_whitespace(self) -> Self
pub fn ignore_changes_within_whitespace(self) -> Self
-db: ignore changes made within whitespace (implies -dl).
Sourcepub fn ignore_all_whitespace(self) -> Self
pub fn ignore_all_whitespace(self) -> Self
-dw: ignore whitespace altogether (implies -dl).
Examples found in repository?
27fn main() -> std::io::Result<()> {
28 let p4 = P4Cli::default();
29
30 // Workspace mode: force a diff against head, use the unified format with
31 // whitespace-insensitive comparison, and limit output to the first 10
32 // files. `force(true)` transitions the command into `WorkspaceMode`, and
33 // `limit(10)` further transitions it into `WorkspaceRegularMode` (where
34 // `-soptions` is unavailable).
35 let mut diff = p4
36 .diff()
37 .force(true)
38 .diff_options(DiffOptionsBuilder::unified(None).ignore_all_whitespace())
39 .limit(10);
40
41 let files = [OsStr::new("//depot/project/src/...")];
42 let output = diff.output_with(&files)?;
43 println!("{}", String::from_utf8_lossy(&output.stdout));
44
45 // Display mode: instead of full diffs, list only the unopened files that
46 // differ from the depot. `display_options` transitions `WorkspaceMode`
47 // into `WorkspaceDisplayMode`, where `-m max` is unavailable.
48 let mut list_changed = p4
49 .diff()
50 .force(true)
51 .display_options(DisplayOptions::UnopenedChanged);
52
53 let output = list_changed.output_with(&files)?;
54 println!("{}", String::from_utf8_lossy(&output.stdout));
55
56 // Stream-spec mode: diff a privately edited stream spec against the head
57 // version of another stream. `stream_spec_mode` transitions the command
58 // into `StreamSpecMode`; the stream spec is passed to `spawn_with`.
59 let mut stream_diff = p4.diff().stream_spec_mode();
60 let mut child = stream_diff.spawn_with(Some("//streams/main@head"))?;
61 child.wait()?;
62
63 Ok(())
64}