From ca44de78e1d4f4127daaab02b6877b01c0893cb7 Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Fri, 25 Aug 2023 08:22:28 -0700 Subject: [PATCH] Group overrides from the same language together No functional change, but makes --list-languages easier to read. Fixes #549 --- src/options.rs | 14 +++++++++++++- src/parse/guess_language.rs | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/options.rs b/src/options.rs index 47f503b55c..593e1a0285 100644 --- a/src/options.rs +++ b/src/options.rs @@ -5,6 +5,7 @@ use std::{env, ffi::OsStr, path::Path, path::PathBuf}; use clap::{crate_authors, crate_description, Arg, Command}; use const_format::formatcp; use crossterm::tty::IsTty; +use itertools::Itertools; use crate::{ display::style::BackgroundColor, @@ -467,7 +468,18 @@ fn parse_overrides_or_die(raw_overrides: &[String]) -> Vec<(LanguageOverride, Ve std::process::exit(EXIT_BAD_ARGUMENTS); } - res + res.into_iter() + .coalesce( + |(prev_lang, mut prev_globs), (current_lang, current_globs)| { + if prev_lang == current_lang { + prev_globs.extend(current_globs); + Ok((prev_lang, prev_globs)) + } else { + Err(((prev_lang, prev_globs), (current_lang, current_globs))) + } + }, + ) + .collect() } /// Parse CLI arguments passed to the binary. diff --git a/src/parse/guess_language.rs b/src/parse/guess_language.rs index ba6eedb5cd..824b3f009a 100644 --- a/src/parse/guess_language.rs +++ b/src/parse/guess_language.rs @@ -73,7 +73,7 @@ pub enum Language { Zig, } -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] pub enum LanguageOverride { Language(Language), PlainText,