jobber 0.1.2-alpha

Minimalistic console work time tracker
use crate::{
    commands::{Cli, Result},
    jobber::JobberDelete,
    print_tip,
};
use clap::Parser;
use color_print::cprintln;

/// Delete a work position.
///
/// Work position will be marked as deleted and can be restored later.
#[derive(Parser, Debug)]
pub(crate) struct DeleteWork {
    /// ID of the job containing the work
    job_id: usize,
    /// Work position
    pos: usize,
}

impl DeleteWork {
    pub(crate) fn run(&self, cli: &Cli) -> Result<()> {
        let mut database = cli.open_database()?;
        database.delete_work(self.job_id, self.pos, true)?;
        cli.close_database(database)?;
        cprintln!(
            "Successfully deleted work position <s>{}</> in job <s>{}</>.",
            self.pos,
            self.job_id
        );
        print_tip!(cli);
        print_tip!(cli, "Use <s>jobber undo</> to restore the work position.",);
        print_tip!(
            cli,
            "Use <s>jobber list work -d</> to list deleted work positions."
        );
        Ok(())
    }
}