Step 2: Page 26-27

This commit is contained in:
2026-02-04 16:23:10 +01:00
parent dd91946fb2
commit 48b0aa8ce1

View File

@@ -1,6 +1,35 @@
use std::env;
use clap::{Parser, Subcommand};
#[derive(Parser)]
#[command(name = "todo")]
#[command(about = "A simple todo list manager")]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
Add { task: String },
List,
Complete { id: usize },
Remove { id: usize },
}
fn main() {
let args: Vec<String> = env::args().collect();
println!("Arguments: {:?}", args);
let cli = Cli::parse();
match cli.command {
Commands::Add { task } => {
println!("Adding task: {}", task);
}
Commands::List => {
println!("Listing tasks");
}
Commands::Complete { id } => {
println!("Completing task with id: {}", id);
}
Commands::Remove { id } => {
println!("Removing task with id: {}", id);
}
}
}