You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
uwuifyy/src/main.rs

90 lines
2.9 KiB
Rust

use clap::{ArgGroup, ErrorKind, IntoApp, Parser};
use uwuify::UwUify;
#[derive(Parser)]
#[clap(author, version, about, long_about = None)]
#[clap(group(ArgGroup::new("uwu").required(true).args(& ["text", "infile"]),))]
struct Args {
/// Text to uwu'ify
#[clap(short, long, required_unless_present_all = ["infile", "outfile"], display_order = 1)]
text: Option<String>,
/// The file to uwu'ify
#[clap(short, long, parse(from_os_str), conflicts_with = "text", requires = "outfile", value_name = "FILE", value_hint = clap::ValueHint::FilePath, display_order = 2)]
infile: Option<std::path::PathBuf>,
/// The file to output uwu'ified text
#[clap(short, long, value_name = "FILE", value_hint = clap::ValueHint::FilePath, display_order = 3)]
outfile: Option<String>,
/// The modifier to determine how many words to be uwu'ified
#[clap(short, long, value_name = "VALUE", default_value = "1", validator = is_between_zero_and_one, display_order = 4)]
3 years ago
words: f64,
/// The modifier for uwu faces e.g hello -> hewwo
#[clap(short, long, value_name = "VALUE", default_value = "0.05", validator = is_between_zero_and_one, display_order = 5)]
3 years ago
faces: f64,
/// The modifier for actions e.g *shuffles over*
#[clap(short, long, value_name = "VALUE", default_value = "0.125", validator = is_between_zero_and_one, display_order = 6)]
3 years ago
actions: f64,
/// The modifier for stutters e.g b-baka!
#[clap(short, long, value_name = "VALUE", default_value = "0.225", validator = is_between_zero_and_one, display_order = 7)]
3 years ago
stutters: f64,
/// Flag to enable/disable random uwu'ifying
#[clap(short, long, display_order = 8)]
random: bool,
}
fn main() {
let args = Args::parse();
let matches = Args::into_app().get_matches();
let supplied_at_runtime = modifiers_supplied_at_runtime(
matches.occurrences_of("faces"),
matches.occurrences_of("actions"),
matches.occurrences_of("stutters"),
);
let uwuify = UwUify::new(
args.text,
args.infile,
args.outfile,
supplied_at_runtime,
args.words,
args.faces,
args.actions,
args.stutters,
args.random,
);
match uwuify.uwuify() {
Ok(_) => (),
Err(err) => {
let mut app = Args::into_app();
app.error(ErrorKind::DisplayHelp, err.to_string()).exit();
}
}
}
3 years ago
fn is_between_zero_and_one(input: &str) -> Result<(), &'static str> {
let value = match input.parse::<f32>() {
Ok(value) => value,
3 years ago
Err(_) => return Err("The value must be a decimal number"),
};
if (0.0..=1.0).contains(&value) {
return Ok(());
}
3 years ago
Err("The value must be between 0.0 and 1.0")
}
fn modifiers_supplied_at_runtime(
faces_occurrences: u64,
actions_occurrences: u64,
stutters_occurrences: u64,
) -> bool {
faces_occurrences > 0 || actions_occurrences > 0 || stutters_occurrences > 0
}