use clap::{Parser, Subcommand};
use rune_morse::{decode, encode};
use std::process::ExitCode;
#[derive(Parser)]
#[command(name = "rune-morse", version, author)]
struct Cli {
#[command(subcommand)]
command: Command,
}
#[derive(Subcommand)]
enum Command {
Encode {
text: String,
},
Decode {
morse: String,
},
}
fn main() -> ExitCode {
let cli = Cli::parse();
match cli.command {
Command::Encode { text } => match encode(&text) {
Ok(morse) => {
println!("{morse}");
ExitCode::SUCCESS
}
Err(error) => {
eprintln!("error: {error}");
ExitCode::FAILURE
}
},
Command::Decode { morse } => match decode(&morse) {
Ok(text) => {
println!("{text}");
ExitCode::SUCCESS
}
Err(error) => {
eprintln!("error: {error}");
ExitCode::FAILURE
}
},
}
}