50 lines
1.0 KiB
Rust
50 lines
1.0 KiB
Rust
use clap::{Parser, Subcommand};
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
#[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 },
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
struct Task {
|
|
id: usize,
|
|
description: String,
|
|
completed: bool,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
struct TodoList {
|
|
tasks: Vec<Task>,
|
|
next_id: usize,
|
|
}
|
|
|
|
fn main() {
|
|
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);
|
|
}
|
|
}
|
|
}
|