Skip to content

Commit

Permalink
Implement diff compatible -L (--label) option.
Browse files Browse the repository at this point in the history
With this, we can use difft as a external diff for Apache Subversion,
in the form:

    svn diff --diff-cmd=difft -x '<at least one difft option>'
  • Loading branch information
futatuki committed Dec 2, 2023
1 parent e01b2f9 commit b553583
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ fn app() -> clap::Command<'static> {
.validator(|s| s.parse::<u32>())
.required(false),
)
.arg(
Arg::new("label").short('L')
.long("label")
.takes_value(true)
.value_name("LABEL")
.max_occurrences(2)
.allow_invalid_utf8(true)
.help("Label of file(s) which should be used for printing instead of PATH(s).")
)
.arg(
Arg::new("width")
.long("width")
Expand Down Expand Up @@ -638,7 +647,25 @@ pub(crate) fn parse_args() -> Mode {
[lhs_path, rhs_path] => {
let lhs_arg = FileArgument::from_cli_argument(lhs_path);
let rhs_arg = FileArgument::from_cli_argument(rhs_path);
let display_path = build_display_path(&lhs_arg, &rhs_arg);
let display_path = if matches.is_present("label") {
let labels: Vec<_> = matches.values_of_os("label").unwrap_or_default().collect();
let (_lhs_display_path, rhs_display_path) = match &labels[..] {
[lhs_display_path, rhs_display_path] => (
lhs_display_path.to_string_lossy().to_string(),
rhs_display_path.to_string_lossy().to_string(),
),
[display_path] => (
display_path.to_string_lossy().to_string(),
display_path.to_string_lossy().to_string(),
),
_ => {
unreachable!("clap has already validated label")
}
};
rhs_display_path
} else {
build_display_path(&lhs_arg, &rhs_arg)
};
(display_path, lhs_arg, rhs_arg, None)
}
[display_path, lhs_tmp_file, _lhs_hash, _lhs_mode, rhs_tmp_file, _rhs_hash, _rhs_mode] => {
Expand Down

0 comments on commit b553583

Please sign in to comment.