Delete reverser directory
This commit is contained in:
parent
764cbfdf48
commit
9cf7f7d3e5
@ -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"] }
|
|
@ -1 +0,0 @@
|
|||||||
pub mod stringer;
|
|
@ -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;
|
|
||||||
}
|
|
@ -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<Commands>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
|
||||||
|
|
||||||
enum Commands {
|
|
||||||
/// Reverses a string
|
|
||||||
Reverse(Reverse),
|
|
||||||
/// Inspects a string
|
|
||||||
Inspect(Inspect),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Args)]
|
|
||||||
struct Reverse {
|
|
||||||
/// The string to reverse
|
|
||||||
string: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Args)]
|
|
||||||
struct Inspect {
|
|
||||||
/// The string to inspect
|
|
||||||
string: Option<String>,
|
|
||||||
|
|
||||||
#[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 => {}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user