diff --git a/reverser/Cargo.toml b/reverser/Cargo.toml deleted file mode 100644 index cb91a4c..0000000 --- a/reverser/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "reverser" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -clap = { version = "4.1.11", features = ["derive"] } diff --git a/reverser/src/api/mod.rs b/reverser/src/api/mod.rs deleted file mode 100644 index 27618bc..0000000 --- a/reverser/src/api/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod stringer; diff --git a/reverser/src/api/stringer.rs b/reverser/src/api/stringer.rs deleted file mode 100644 index 3b4ce7b..0000000 --- a/reverser/src/api/stringer.rs +++ /dev/null @@ -1,20 +0,0 @@ -pub fn reverse(input: &String) -> String { - return input.chars().rev().collect(); -} - -pub fn inspect(input: &String, digits: bool) -> (i32, String) { - if !digits { - return (input.len() as i32, String::from("char")); - } - return (inspect_numbers(input), String::from("digit")); -} - -fn inspect_numbers(input: &String) -> i32 { - let mut count = 0; - for c in input.chars() { - if c.is_digit(10) { - count += 1; - } - } - return count; -} diff --git a/reverser/src/main.rs b/reverser/src/main.rs deleted file mode 100644 index 440eef2..0000000 --- a/reverser/src/main.rs +++ /dev/null @@ -1,72 +0,0 @@ -use ::clap::{Parser, Subcommand, Args}; - -mod api; - -#[derive(Parser)] -#[command(author, version)] -#[command(about = "stringer - a simple CLI to reverse strings", long_about = "stringer is a simple, nimble cli for reversing and inspecting strings")] - -struct Cli { - #[command(subcommand)] - command: Option, -} - -#[derive(Subcommand)] - -enum Commands { - /// Reverses a string - Reverse(Reverse), - /// Inspects a string - Inspect(Inspect), -} - -#[derive(Args)] -struct Reverse { - /// The string to reverse - string: Option, -} - -#[derive(Args)] -struct Inspect { - /// The string to inspect - string: Option, - - #[arg(short = 'd', long = "digits")] - only_digits: bool, -} - -fn main() { - let cli = Cli::parse(); - - match &cli.command { - Some(Commands::Reverse(name)) => { - match name.string { - Some(ref _name) => { - let reverse = api::stringer::reverse(_name); - println!("{}", reverse); - } - None => { - println!("Please provide a string to reverse"); - } - } - } - Some(Commands::Inspect(name)) => { - match name.string { - Some(ref _name) => { - let (res, kind) = api::stringer::inspect(_name, name.only_digits); - - let mut plural_s = "s"; - if res == 1 { - plural_s = ""; - } - - println!("{:?} has {} {}{}.", _name, res, kind, plural_s); - } - None => { - println!("Please provide a string to inspect"); - } - } - } - None => {} - } -}