use crate::error::ClewError;
use clap::{Parser, Subcommand};
#[derive(Parser)]
#[command(
name = "clew",
version,
about = "Lightweight git-native project management"
)]
pub struct Cli {
#[command(subcommand)]
pub command: Option<Command>,
}
#[derive(Subcommand)]
pub enum Command {
Init,
#[command(after_help = r#"Examples:
clew new "Add OAuth route handlers"
clew new --ready "Add OAuth route handlers"
clew new "Add OAuth route handlers" < body.md
printf 'Body text here' | clew new "Add OAuth route handlers"
If stdin is non-interactive, it is read verbatim as the increment body."#)]
New {
title: String,
#[arg(long)]
ready: bool,
#[arg(long)]
parent: Option<u32>,
#[arg(long = "tag")]
tags: Vec<String>,
},
#[command(alias = "view")]
Show { id: String },
List {
#[arg(long)]
tag: Option<String>,
#[arg(long)]
status: Option<String>,
#[arg(short = 'a', long)]
all: bool,
},
Start { id: String },
Block { id: String, reason: String },
Unblock { id: String },
Tag {
id: String,
#[arg(required = true)]
tags: Vec<String>,
},
Untag {
id: String,
#[arg(required = true)]
tags: Vec<String>,
},
Done { id: String },
Abandon { id: String, reason: Option<String> },
Reopen { id: String },
Next {
#[arg(long)]
start: bool,
},
Path,
Lint,
Renumber { old: u32, new: u32 },
}
impl Cli {
pub fn dispatch(self) -> Result<(), ClewError> {
match self.command {
None => {
eprintln!("Run `clew --help` for usage.");
Ok(())
}
Some(Command::Init) => crate::commands::init::run(),
Some(Command::New {
title,
ready,
parent,
tags,
}) => crate::commands::new::run(&title, ready, parent, &tags),
Some(Command::Show { id }) => crate::commands::show::run(&id),
Some(Command::List { tag, status, all }) => {
crate::commands::list::run(tag.as_deref(), status.as_deref(), all)
}
Some(Command::Start { id }) => crate::commands::start::run(&id),
Some(Command::Block { id, reason }) => crate::commands::block::run(&id, &reason),
Some(Command::Unblock { id }) => crate::commands::unblock::run(&id),
Some(Command::Tag { id, tags }) => crate::commands::tag::run(&id, &tags),
Some(Command::Untag { id, tags }) => crate::commands::untag::run(&id, &tags),
Some(Command::Done { id }) => crate::commands::done::run(&id),
Some(Command::Abandon { id, reason }) => {
crate::commands::abandon::run(&id, reason.as_deref())
}
Some(Command::Reopen { id }) => crate::commands::reopen::run(&id),
Some(Command::Next { start }) => crate::commands::next::run(start),
Some(Command::Lint) => crate::commands::lint::run(),
Some(_) => Err(ClewError::Unimplemented),
}
}
}