ncase 0.1.1

Enforce a case style
Documentation
use std::io::BufRead;

use regex::Regex;

use ncase::Words;

#[derive(argh::FromArgs)]
/// Enforce a case style.
struct Cli {
    /// define the separator regex
    #[argh(option, short = 'F')]
    separator: Option<Regex>,

    /// enforce camelCase
    #[argh(switch, short = 'c')]
    camel: bool,

    /// enforce PascalCase
    #[argh(switch, short = 'P')]
    pascal: bool,

    /// enforce kebab-case
    #[argh(switch, short = 'k')]
    kebab: bool,

    /// enforce SCREAMING-KEBAB-CASE
    #[argh(switch, short = 'K')]
    screaming_kebab: bool,

    /// enforce lower case
    #[argh(switch, short = 'l')]
    lower: bool,

    /// enforce UPPER CASE
    #[argh(switch, short = 'U')]
    upper: bool,

    /// enforce snake_case
    #[argh(switch, short = 's')]
    snake: bool,

    /// enforce SCREAMING_SNAKE_CASE
    #[argh(switch, short = 'S')]
    screaming_snake: bool,

    /// enforce Title Case
    #[argh(switch, short = 't')]
    title: bool,

    /// enforce tOGGLE cASE
    #[argh(switch, short = 'T')]
    toggle: bool,

    /// enforce rANdOm cASe
    #[argh(switch, short = 'r')]
    _random: bool,

    /// the subject string; if absent, read lines from the stdin
    #[argh(positional)]
    args: Vec<String>,
}

fn main() -> anyhow::Result<()> {
    let cli: Cli = argh::from_env();

    if !cli.args.is_empty() {
        println!("{}", ncase(&cli.args.join(" "), &cli));
    } else {
        for line_res in std::io::stdin().lock().lines() {
            println!("{}", ncase(&line_res?, &cli));
        }
    }
    Ok(())
}

#[allow(clippy::needless_return)]
fn ncase(s: &str, cli: &Cli) -> String {
    let w = match &cli.separator {
        Some(sep) => Words::with_separator(s, sep),
        None => Words::from(s),
    };
    #[allow(clippy::suspicious_else_formatting)]
    #[rustfmt::skip]
    return
        if cli.camel           { w.camel()           } else
        if cli.pascal          { w.pascal()          } else
        if cli.kebab           { w.kebab()           } else
        if cli.screaming_kebab { w.screaming_kebab() } else
        if cli.lower           { w.lower()           } else
        if cli.upper           { w.upper()           } else
        if cli.snake           { w.snake()           } else
        if cli.screaming_snake { w.screaming_snake() } else
        if cli.title           { w.title()           } else
        if cli.toggle          { w.toggle()          } else
                               { w.random()          };
}