Cwap awgument awtimization UwU

pull/2/head
Isaac Mills 3 years ago
parent 71f408ef58
commit 29e9d92768
No known key found for this signature in database
GPG Key ID: B67D7410F33A0F61

@ -1,4 +1,4 @@
use clap::{ArgGroup, ErrorKind, IntoApp, Parser};
use clap::{Arg, ArgGroup, ErrorKind};
use uwuify::UwUify;
@ -8,47 +8,100 @@ macro_rules! modifiers_supplied_at_runtime {
};
}
#[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)]
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)]
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)]
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)]
stutters: f64,
/// Flag to enable/disable random uwu'ifying
#[clap(short, long, display_order = 8)]
random: bool,
macro_rules! app {
() => {
clap::App::new(env!("CARGO_PKG_NAME"))
.author(env!("CARGO_PKG_AUTHORS"))
.version(env!("CARGO_PKG_VERSION"))
.about(env!("CARGO_PKG_DESCRIPTION"))
.long_about(None)
.group(
ArgGroup::new("uwu")
.required(true)
.args(&["text", "infile"]),
)
.arg(
Arg::new("text")
.help("Text to uwu'ify")
.short('t')
.long("text")
.required_unless_present_all(["infile", "outfile"])
.display_order(1),
)
.arg(
Arg::new("infile")
.help("The file to uwu'ify")
.short('i')
.long("infile")
.conflicts_with("text")
.requires("outfile")
.value_name("FILE")
.value_hint(clap::ValueHint::FilePath)
.display_order(2),
)
.arg(
Arg::new("outfile")
.help("The file to output uwu'ified text")
.short('o')
.long("outfile")
.value_name("FILE")
.value_hint(clap::ValueHint::FilePath)
.display_order(3),
)
.arg(
Arg::new("words")
.help("The modifier to determine how many words to be uwu'ified")
.short('w')
.long("words")
.value_name("VALUE")
.default_value("1")
.validator(is_between_zero_and_one)
.display_order(4),
)
.arg(
Arg::new("faces")
.help("The modifier for uwu faces e.g hello -> hewwo")
.short('f')
.long("faces")
.value_name("VALUE")
.default_value("0.05")
.validator(is_between_zero_and_one)
.display_order(5),
)
.arg(
Arg::new("actions")
.help("The modifier for actions e.g *shuffles over*")
.short('a')
.long("actions")
.value_name("VALUE")
.default_value("0.125")
.validator(is_between_zero_and_one)
.display_order(6),
)
.arg(
Arg::new("stutters")
.help("The modifier for stutters e.g b-baka!")
.short('s')
.long("stutters")
.value_name("VALUE")
.default_value("0.225")
.validator(is_between_zero_and_one)
.display_order(7),
)
.arg(
Arg::new("random")
.help("Flag to enable/disable random uwu'ifying")
.short('r')
.long("random")
.display_order(8),
)
};
}
fn main() {
let matches = Args::into_app().get_matches();
let matches = app!().get_matches();
let uwuify = UwUify::new(
match UwUify::new(
matches.value_of("text"),
matches.value_of("infile").map(|f| std::path::Path::new(f)),
matches.value_of("outfile"),
@ -57,17 +110,17 @@ fn main() {
matches.occurrences_of("actions"),
matches.occurrences_of("stutters")
),
matches.value_of_t("words").unwrap_or_else(|e| e.exit()),
matches.value_of_t("faces").unwrap_or_else(|e| e.exit()),
matches.value_of_t("actions").unwrap_or_else(|e| e.exit()),
matches.value_of_t("stutters").unwrap_or_else(|e| e.exit()),
matches.value_of_t("random").unwrap_or_else(|e| e.exit()),
);
match uwuify.uwuify() {
matches.value_of_t_or_exit("words"),
matches.value_of_t_or_exit("faces"),
matches.value_of_t_or_exit("actions"),
matches.value_of_t_or_exit("stutters"),
matches.is_present("random"),
)
.uwuify()
{
Ok(_) => (),
Err(err) => {
let mut app = Args::into_app();
app.error(ErrorKind::DisplayHelp, err).exit();
app!().error(ErrorKind::DisplayHelp, err).exit();
}
}
}

Loading…
Cancel
Save