wekan_cli/commands/
self_management.rs1use clap::{Args, Subcommand};
2
3use crate::{
4 command_result::{CancellationSuccess, CommandSuccess, DestructiveOperation},
5 error::AppError,
6 input::ConfirmationProvider,
7 update::{self, UpdateService},
8};
9
10#[derive(Debug, Args)]
11pub struct SelfArgs {
12 #[command(subcommand)]
13 pub command: SelfCommand,
14}
15
16#[derive(Debug, Subcommand)]
17pub enum SelfCommand {
18 Update(UpdateArgs),
20}
21
22#[derive(Debug, Args)]
23pub struct UpdateArgs {
24 #[arg(long, conflicts_with = "yes")]
26 pub check: bool,
27 #[arg(long)]
29 pub yes: bool,
30}
31
32pub(crate) fn dispatch(
33 command: SelfCommand,
34 service: UpdateService,
35 confirmation: &dyn ConfirmationProvider,
36) -> impl std::future::Future<Output = Result<CommandSuccess, AppError>> + Send + '_ {
37 Box::pin(async move {
38 let SelfCommand::Update(args) = command;
39 match service.manual(args.check, args.yes, confirmation).await? {
40 update::ManualOutcome::Complete(data) => Ok(CommandSuccess::SelfUpdate(data)),
41 update::ManualOutcome::Cancelled => Ok(CommandSuccess::Cancelled(
42 CancellationSuccess::new(DestructiveOperation::SelfUpdate),
43 )),
44 }
45 })
46}