diff options
| author | Strubbelkopp <[email protected]> | 2025-07-25 12:18:36 +0200 |
|---|---|---|
| committer | Strubbelkopp <[email protected]> | 2025-07-25 12:18:36 +0200 |
| commit | 473d5d0173b80917692bb316d8c681be16355510 (patch) | |
| tree | 25e418e854fd3d18acc922283925fce58ef5d196 | |
| parent | 93e431196b8f9d8a66ce1ef99b2c92953ce12a3a (diff) | |
| download | mikusays-c-473d5d0173b80917692bb316d8c681be16355510.tar.gz mikusays-c-473d5d0173b80917692bb316d8c681be16355510.zip | |
Add clap for more advanced argument parsing
| -rw-r--r-- | Cargo.toml | 4 | ||||
| -rw-r--r-- | src/main.rs | 19 |
2 files changed, 14 insertions, 9 deletions
@@ -1,9 +1,11 @@ [package] name = "mikusays" -version = "0.1.1" +version = "0.1.2" edition = "2024" +description = "A \"cowsay\" clone with Hatsune Miku ASCII art and speech bubbles." [dependencies] crossterm = "0.29" unicode-width = "0.2" rand = "0.9" +clap = { version = "4.5.41", features = ["derive"] } diff --git a/src/main.rs b/src/main.rs index e4d1b6e..d6313fa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,20 +1,23 @@ use crossterm::terminal::size; use std::env; use unicode_width::UnicodeWidthStr; +use clap::Parser; mod mikuart; use mikuart::get_miku_art; -fn main() -> Result<(), Box<dyn std::error::Error>> { - let args: Vec<String> = env::args().collect(); +#[derive(Parser)] +#[command(version, about, long_about = None)] +struct Args { + /// Text to display in the speech bubble + text: String, - if args.len() == 1 { - println!("Usage: mikusays <text>"); - println!("Example: mikusays \"Hello, World!\""); - return Ok(()); - } +} - let text = args[1..].join(" "); +fn main() -> Result<(), Box<dyn std::error::Error>> { + let args = Args::parse(); + + let text = args.text; draw_miku_says(&text)?; Ok(()) |
