use clap::{Args, Subcommand};
use crate::{
command_result::{CancellationSuccess, CommandSuccess, DestructiveOperation},
error::AppError,
input::ConfirmationProvider,
update::{self, UpdateService},
};
#[derive(Debug, Args)]
pub struct SelfArgs {
#[command(subcommand)]
pub command: SelfCommand,
}
#[derive(Debug, Subcommand)]
pub enum SelfCommand {
Update(UpdateArgs),
}
#[derive(Debug, Args)]
pub struct UpdateArgs {
#[arg(long, conflicts_with = "yes")]
pub check: bool,
#[arg(long)]
pub yes: bool,
}
pub(crate) fn dispatch(
command: SelfCommand,
service: UpdateService,
confirmation: &dyn ConfirmationProvider,
) -> impl std::future::Future<Output = Result<CommandSuccess, AppError>> + Send + '_ {
Box::pin(async move {
let SelfCommand::Update(args) = command;
match service.manual(args.check, args.yes, confirmation).await? {
update::ManualOutcome::Complete(data) => Ok(CommandSuccess::SelfUpdate(data)),
update::ManualOutcome::Cancelled => Ok(CommandSuccess::Cancelled(
CancellationSuccess::new(DestructiveOperation::SelfUpdate),
)),
}
})
}