use anyhow::Result; use clap::Parser; mod command; mod handlers; mod util; use command::*; use handlers::*; use util::*; /// Die quietly when stdout is closed early, the way every other Unix tool does. /// /// Rust sets `SIGPIPE` to `SIG_IGN` at startup, which turns a closed pipe into an /// io error that `println!` panics on. So `worklane ls | head -3` printed a panic /// and a backtrace instead of three lines, which is both alarming and easy to /// mistake for a real fault. Restoring the default handler makes `| head` behave. /// /// The cost is that a truncated pipe now kills the process with signal 13 rather /// than returning a code, so `pipefail` sees 141 instead of 101. That is what /// `head` and `sort` do, and it is recorded in the README. fn quiet_broken_pipe() { // SAFETY: setting a signal disposition to the default is always valid, and // this runs before any thread is spawned. unsafe { libc::signal(libc::SIGPIPE, libc::SIG_DFL); } } fn main() -> Result<()> { // Before any output, so no write can beat it to a closed pipe. quiet_broken_pipe(); let cli = Cli::parse(); let start = std::env::current_dir()?; match cli.command { Command::Init => cmd_init(&start), Command::Add { title, description, acceptance, plan, tags, due, owner, priority, } => cmd_add( &title, &description, &acceptance, &plan, &tags, &due, &owner, priority, &start, ), Command::Ls { status, priority } => { let worklane_dir = find_worklane_dir(&start)?; cmd_ls(&status, priority, &worklane_dir) } Command::Show { id } => { let worklane_dir = find_worklane_dir(&start)?; cmd_show(&id, &worklane_dir) } Command::Mv { ticket, status, force, } => cmd_mv(&ticket, &status, force, &start), Command::Set(args) => cmd_set(&args, &start), Command::Append(args) => cmd_append(&args, &start), Command::Comment { ticket, body, owner } => cmd_comment(&ticket, &body, &owner, &start), } }