Step 2: Page 26-27
This commit is contained in:
35
src/main.rs
35
src/main.rs
@@ -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() {
|
fn main() {
|
||||||
let args: Vec<String> = env::args().collect();
|
let cli = Cli::parse();
|
||||||
println!("Arguments: {:?}", args);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user