From 1bd7e65a94289e444f067f4da28935df0baca9be Mon Sep 17 00:00:00 2001 From: Fuwn Date: Thu, 20 May 2021 01:58:02 +0000 Subject: feat(nitrous): :star: --- src/cli.rs | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/cli.rs (limited to 'src/cli.rs') 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::() + .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), + ), + ]) + } +} -- cgit v1.2.3