use std::process::ExitCode;
use std::sync::Arc;
use clap::Subcommand;
pub mod login;
pub mod logout;
pub mod me;
use crate::config::Config;
use crate::Result;
#[derive(Debug, Clone, PartialEq, Subcommand)]
#[command(author, rename_all = "kebab-case")]
pub enum Command {
Login(login::Opts),
Logout(logout::Opts),
Me(me::Opts),
}
impl Command {
pub fn may_need_user_session(&self) -> bool {
match self {
Command::Login(opts) => opts.may_need_user_session(),
Command::Logout(opts) => opts.may_need_user_session(),
Command::Me(opts) => opts.may_need_user_session(),
}
}
}
pub async fn handle(
config: Config,
mega: &mut Arc<mega::Client>,
opts: Command,
) -> Result<ExitCode> {
match opts {
Command::Login(opts) => login::handle(config, mega, opts).await,
Command::Logout(opts) => logout::handle(config, mega, opts).await,
Command::Me(opts) => me::handle(config, mega, opts).await,
}
}