use camino::Utf8PathBuf;
use clap::{Args, Parser, Subcommand, ValueEnum};
use lib_tasker::todos::State;
#[derive(Debug, Parser)]
#[command(
name = "Tasker CLI",
author,
version,
about,
long_about = None,
help_template = "\
{before-help}{name} {version}
{author-with-newline}{about-with-newline}
{usage-heading} {usage}
{all-args}{after-help}"
)]
pub struct Cli {
#[command(subcommand)]
pub command: Option<Command>,
#[arg(long = "todo-file")]
pub to_do_file: Option<Utf8PathBuf>,
#[arg(long)]
pub config_file: Option<Utf8PathBuf>,
}
#[derive(Debug, Subcommand)]
#[command(help_template(
"\
{name}
{about-with-newline}
{usage-heading} {usage}
{all-args}"
))]
pub enum Command {
#[command(arg_required_else_help = true, visible_alias = "a")]
Add(AddToDo),
#[command(
arg_required_else_help = true,
name = "addm",
visible_alias = "am"
)]
AddMultiple(AddMultipleToDo),
#[command(visible_alias = "c")]
Clean,
#[command(arg_required_else_help = true, visible_alias = "d")]
Delete(DeleteToDo),
#[command(arg_required_else_help = true, visible_alias = "e")]
Edit(EditToDo),
#[command(visible_alias = "l")]
List(ListToDo),
#[command(visible_alias = "p")]
Paths,
#[command(arg_required_else_help = true, visible_alias = "t")]
Toggle(ToggleToDo),
}
#[derive(Args, Debug)]
#[command(help_template(
"\
{name}
{about-with-newline}
{usage-heading} {usage}
{all-args}"
))]
pub struct AddToDo {
pub description: String,
#[arg(short, long)]
pub project: Option<String>,
#[arg(short, long)]
pub tag: Option<Vec<String>>,
}
#[derive(Args, Debug)]
#[command(help_template(
"\
{name}
{about-with-newline}
{usage-heading} {usage}
{all-args}"
))]
pub struct AddMultipleToDo {
pub descriptions: Vec<String>,
#[arg(short, long)]
pub project: Option<String>,
#[arg(short, long)]
pub tag: Option<Vec<String>>,
}
#[derive(Args, Debug)]
#[command(help_template(
"\
{name}
{about-with-newline}
{usage-heading} {usage}
{all-args}"
))]
pub struct ToggleToDo {
#[arg(value_enum)]
pub state: ToggleState,
#[arg(name = "TO-DOS")]
pub tasks: Vec<usize>,
}
#[derive(Debug, ValueEnum, Clone, Copy)]
pub enum ToggleState {
#[value(name = "todo", alias = "t")]
ToDo,
#[value(alias = "dg")]
Doing,
#[value(alias = "dn")]
Done,
#[value(name = "wait", alias = "w")]
Waiting,
}
impl From<ToggleState> for State {
fn from(value: ToggleState) -> Self {
match value {
ToggleState::ToDo => Self::ToDo,
ToggleState::Doing => Self::Doing,
ToggleState::Done => Self::Done,
ToggleState::Waiting => Self::Waiting,
}
}
}
#[derive(Args, Debug)]
#[command(help_template(
"\
{name}
{about-with-newline}
{usage-heading} {usage}
{all-args}"
))]
pub struct EditToDo {
#[arg(name = "TO-DO")]
pub task: usize,
#[arg(short, long)]
pub description: Option<String>,
#[arg(short, long, value_enum)]
pub state: Option<ToggleState>,
#[arg(short, long)]
pub project: Option<String>,
#[arg(short, long)]
pub tags: Option<Vec<String>>,
}
#[derive(Args, Debug)]
#[command(help_template(
"\
{name}
{about-with-newline}
{usage-heading} {usage}
{all-args}"
))]
pub struct DeleteToDo {
#[arg(name = "TASKS")]
pub tasks: Vec<usize>,
}
#[derive(Args, Debug)]
#[command(help_template(
"\
{name}
{about-with-newline}
{usage-heading} {usage}
{all-args}"
))]
pub struct ListToDo {
#[arg(short = 'S', long, value_enum)]
pub sort_by: Option<SortToDo>,
#[arg(short, long)]
pub description: Option<String>,
#[arg(short, long)]
pub state: Option<ToggleState>,
#[arg(short, long)]
pub tag: Option<Vec<String>>,
#[arg(short, long)]
pub project: Option<String>,
}
#[derive(Debug, ValueEnum, Clone, Copy)]
pub enum SortToDo {
#[value(alias = "desc", alias = "d")]
Description,
#[value(alias = "pro", alias = "p")]
Project,
#[value(alias = "s")]
State,
#[value(alias = "i")]
ID,
}