Repository: sharkdp/bat
File: src/app.rs (Rust)

Code before:
                Some("auto") | _ => self.interactive_output,
            },
            paging_mode: match self.matches.value_of("paging") {
                Some("always") => PagingMode::Always,
                Some("never") => PagingMode::Never,
                Some("auto") | _ => if files.contains(&None) {
                    // If we are reading from stdin, only enable paging if we write to an
                    // interactive terminal and if we do not *read* from an interactive
                    // terminal.
                    if self.interactive_output && !atty::is(Stream::Stdin) {
                        PagingMode::QuitIfOneScreen
                    } else {
                        PagingMode::Never
                    }
                } else {
                    if self.interactive_output {
                        PagingMode::QuitIfOneScreen
                    } else {
                        PagingMode::Never
                    }
                },
            },
            term_width: Term::stdout().size().1 as usize,
            files,
            theme: self.matches.value_of("theme"),
            line_range: get_ranges(self.matches.value_of("line-range")),
        })
    }

    fn files(&self) -> Vec<Option<&str>> {
        self.matches
            .values_of("FILE")
            .map(|values| {
                values
                    .map(|filename| {
                        if filename == "-" {
                            None
                        } else {
                            Some(filename)
                        }
                    })
                    .collect()
            })
            .unwrap_or_else(|| vec![None]) // read from stdin (None) if no args are given
    }

    fn output_components(&self) -> Result<OutputComponents> {
        let matches = &self.matches;
        Ok(OutputComponents(if matches.is_present("number") {
            [OutputComponent::Numbers].iter().cloned().collect()
        } else {

Review comment (suggestion):
I would write this as `self.matches.value_of("line-range").map(get_ranges)`. This would allow us to get rid of the outermost `match` in `get_ranges`. The signature would change to `fn get_ranges(value: &str) -> ..`.

Code after:
            colored_output: match self.matches.value_of("color") {
                Some("always") => true,
                Some("never") => false,
                Some("auto") | _ => self.interactive_output,
            },
            paging_mode: match self.matches.value_of("paging") {
                Some("always") => PagingMode::Always,
                Some("never") => PagingMode::Never,
                Some("auto") | _ => if files.contains(&None) {
                    // If we are reading from stdin, only enable paging if we write to an
                    // interactive terminal and if we do not *read* from an interactive
                    // terminal.
                    if self.interactive_output && !atty::is(Stream::Stdin) {
                        PagingMode::QuitIfOneScreen
                    } else {
                        PagingMode::Never
                    }
                } else {
                    if self.interactive_output {
                        PagingMode::QuitIfOneScreen
                    } else {
                        PagingMode::Never
                    }
                },
            },
            term_width: Term::stdout().size().1 as usize,
            files,
            theme: self.matches.value_of("theme"),
            line_range: transpose(self.matches.value_of("line-range").map(LineRange::from))?,
        })
    }

    fn files(&self) -> Vec<Option<&str>> {
        self.matches
            .values_of("FILE")
            .map(|values| {
                values
                    .map(|filename| {
                        if filename == "-" {
                            None
                        } else {
                            Some(filename)
                        }
                    })
                    .collect()
            })
            .unwrap_or_else(|| vec![None]) // read from stdin (None) if no args are given
    }

    fn output_components(&self) -> Result<OutputComponents> {
        let matches = &self.matches;