//! Sets of extensions for use with [Parameter](crate::parameters::Parameters)'s `-E` flag. use clap::Clap; #[derive(Clap, PartialEq, Debug)] pub enum ExtensionSet { /// Extensions used for image file formats, such as `png`, `jpeg`, `webp`, etc. Images, /// Extensions used for audio file formats, such as `mp3`, `ogg`, `flac`, etc. Audio, /// Extensions used for video file formats, such as `mkv`, `mp4`, `mov`, etc. Videos, /// Extensions used for media file formats. This acts as a combination of the [Images](ExtensionSet::Images), /// [Audio](ExtensionSet::Audio) and [Videos](ExtensionSet::Videos) variants. Media, /// Extensions used for document file formats, such as `pdf`, `odt`, `docx`, etc. Documents, /// Extensions used for text file formats, such as `txt`, `toml`, `html`, etc. Text, /// Extensions used for archive file formats, such as `zip`, `zst`, `gz`, etc. Archives, /// Extensions used for system file formats, such as `mbr`, `crash`, `dll`, etc. System, } impl ExtensionSet { /// The list of known extensions for this `ExtensionSet`. pub fn extensions(&self) -> Vec<&str> { match self { Self::Images => mime_guess::get_mime_extensions_str("image/*").unwrap().to_vec(), Self::Audio => mime_guess::get_mime_extensions_str("audio/*").unwrap().to_vec(), Self::Videos => mime_guess::get_mime_extensions_str("video/*").unwrap().to_vec(), Self::Media => [ Self::Images.extensions(), Self::Audio.extensions(), Self::Videos.extensions(), ] .concat(), Self::Documents => vec![ "pdf", "doc", "docx", "ppt", "pptx", "xls", "xlsx", "csv", "tsv", "odt", "ods", "odp", "oda", "rtf", "ps", "pages", "key", "numbers", ], Self::Text => mime_guess::get_mime_extensions_str("text/*").unwrap().to_vec(), // many compressed file types follow the name scheme "application/x.+compressed.*" - maybe this can be used // somehow to extract extensions for compressed files from mime_guess? Self::Archives => vec!["zip", "tar", "gz", "zst", "xz", "rar", "7z", "bz", "bz2", "tgz", "rpa"], Self::System => vec!["com", "dll", "exe", "sys", "reg", "nt", "cpl", "msi", "efi", "bio", "rcv", "mbr", "sbf", "grub", "ko", "dylib", "pdb", "hdmp", "crash", ], Self::Archives => vec!["zip", "tar", "gz", "zst", "xz", "rar", "7z", "bz", "bz2", "tgz"], } } }