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

Loading…
Cancel
Save