From f76db7fa4bc93837c12d3ab4ffb4a493447e0036 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Fri, 16 Aug 2024 23:20:07 +0900 Subject: [PATCH] cli: flatten diff-args-to-formats translation I'll add more parameters to color-words diffs, and the format variant will no longer be trivially constructible. --- cli/src/diff_util.rs | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/cli/src/diff_util.rs b/cli/src/diff_util.rs index 3ebfc9a8d..8a926f7e2 100644 --- a/cli/src/diff_util.rs +++ b/cli/src/diff_util.rs @@ -137,27 +137,27 @@ fn diff_formats_from_args( settings: &UserSettings, args: &DiffFormatArgs, ) -> Result, config::ConfigError> { - let mut formats = [ - (args.summary, DiffFormat::Summary), - (args.types, DiffFormat::Types), - (args.name_only, DiffFormat::NameOnly), - ( - args.git, - DiffFormat::Git { - context: args.context.unwrap_or(DEFAULT_CONTEXT_LINES), - }, - ), - ( - args.color_words, - DiffFormat::ColorWords { - context: args.context.unwrap_or(DEFAULT_CONTEXT_LINES), - }, - ), - (args.stat, DiffFormat::Stat), - ] - .into_iter() - .filter_map(|(arg, format)| arg.then_some(format)) - .collect_vec(); + let mut formats = Vec::new(); + if args.summary { + formats.push(DiffFormat::Summary); + } + if args.types { + formats.push(DiffFormat::Types); + } + if args.name_only { + formats.push(DiffFormat::NameOnly); + } + if args.git { + let context = args.context.unwrap_or(DEFAULT_CONTEXT_LINES); + formats.push(DiffFormat::Git { context }); + } + if args.color_words { + let context = args.context.unwrap_or(DEFAULT_CONTEXT_LINES); + formats.push(DiffFormat::ColorWords { context }); + } + if args.stat { + formats.push(DiffFormat::Stat); + } if let Some(name) = &args.tool { let tool = merge_tools::get_external_tool_config(settings, name)? .unwrap_or_else(|| ExternalMergeTool::with_program(name));