use chrono::NaiveDate;
use clap::{Parser, Subcommand};
#[derive(Parser, Debug)]
#[command(
author = "0xgsvs",
version = "0.1.0",
about = "A simple command-line task manager written in Rust.",
long_about = "Organize your tasks efficiently from the terminal. Add, list, complete, and remove tasks with ease."
)]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
}
#[derive(Subcommand, Debug)]
pub enum Commands {
Add {
description: String,
#[arg(short, long, value_parser = parse_due_date)]
due: Option<NaiveDate>,
},
List {
#[arg(short, long)]
all: bool,
},
Complete {
id: u32,
},
Undone {
id: u32,
},
Remove {
id: u32,
},
Clear {
#[arg(short, long)]
yes: bool,
},
}
fn parse_due_date(s: &str) -> Result<NaiveDate, String> {
NaiveDate::parse_from_str(s, "%Y-%m-%d")
.map_err(|_| format!("Date format must be YYYY-MM-DD. Failed to parse: '{}'", s))
}