aboutsummaryrefslogtreecommitdiff
path: root/src/cli.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/cli.rs')
-rw-r--r--src/cli.rs60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/cli.rs b/src/cli.rs
new file mode 100644
index 0000000..fe43439
--- /dev/null
+++ b/src/cli.rs
@@ -0,0 +1,60 @@
+// Copyleft (ɔ) 2021-2021 Fuwn
+// SPDX-License-Identifier: GPL-3.0-only
+
+use structopt::{
+ clap,
+ clap::{App, Arg, SubCommand},
+};
+
+use crate::nitrous::Nitrous;
+
+pub struct Cli;
+impl Cli {
+ pub async fn execute() {
+ let matches = Self::cli().get_matches();
+
+ if matches.is_present("generate") {
+ Nitrous::generate(
+ matches
+ .subcommand_matches("generate")
+ .unwrap()
+ .value_of("amount")
+ .unwrap()
+ .to_string()
+ .parse::<usize>()
+ .unwrap(),
+ );
+ } else if matches.is_present("check") {
+ Nitrous::check(
+ matches
+ .subcommand_matches("check")
+ .unwrap()
+ .value_of("file")
+ .unwrap(),
+ )
+ .await;
+ }
+ }
+
+ fn cli() -> App<'static, 'static> {
+ App::new(env!("CARGO_PKG_NAME"))
+ .about(env!("CARGO_PKG_DESCRIPTION"))
+ .version(env!("CARGO_PKG_VERSION"))
+ .author(env!("CARGO_PKG_AUTHORS"))
+ .setting(clap::AppSettings::SubcommandRequiredElseHelp)
+ .subcommands(vec![
+ SubCommand::with_name("generate").alias("gen").arg(
+ Arg::with_name("amount")
+ .required(true)
+ .index(1)
+ .takes_value(true),
+ ),
+ SubCommand::with_name("check").arg(
+ Arg::with_name("file")
+ .required(true)
+ .takes_value(true)
+ .index(1),
+ ),
+ ])
+ }
+}