use std::process::ExitCode;
use std::sync::Arc;
use clap::Subcommand;
pub mod auth;
pub mod compare;
pub mod config;
pub mod delete;
pub mod follow;
pub mod get;
pub mod list;
pub mod mkdir;
pub mod put;
pub mod rename;
pub mod tree;
use crate::config::Config;
use crate::Result;
#[derive(Debug, Clone, PartialEq, Subcommand)]
#[command(author, rename_all = "kebab-case")]
pub enum Command {
#[command(subcommand)]
Auth(auth::Command),
#[command(subcommand)]
Config(config::Command),
Get(get::Opts),
Put(put::Opts),
List(list::Opts),
Tree(tree::Opts),
Mkdir(mkdir::Opts),
Rename(rename::Opts),
Delete(delete::Opts),
Follow(follow::Opts),
Compare(compare::Opts),
}
impl Command {
pub fn may_need_user_session(&self) -> bool {
match self {
Command::Auth(opts) => opts.may_need_user_session(),
Command::Config(opts) => opts.may_need_user_session(),
Command::Get(opts) => opts.may_need_user_session(),
Command::Put(opts) => opts.may_need_user_session(),
Command::List(opts) => opts.may_need_user_session(),
Command::Tree(opts) => opts.may_need_user_session(),
Command::Mkdir(opts) => opts.may_need_user_session(),
Command::Rename(opts) => opts.may_need_user_session(),
Command::Delete(opts) => opts.may_need_user_session(),
Command::Follow(opts) => opts.may_need_user_session(),
Command::Compare(opts) => opts.may_need_user_session(),
}
}
}
pub async fn handle(
config: Config,
mega: &mut Arc<mega::Client>,
opts: Command,
) -> Result<ExitCode> {
match opts {
Command::Auth(opts) => auth::handle(config, mega, opts).await,
Command::Config(opts) => config::handle(config, mega, opts).await,
Command::Get(opts) => get::handle(config, mega, opts).await,
Command::Put(opts) => put::handle(config, mega, opts).await,
Command::List(opts) => list::handle(config, mega, opts).await,
Command::Tree(opts) => tree::handle(config, mega, opts).await,
Command::Mkdir(opts) => mkdir::handle(config, mega, opts).await,
Command::Rename(opts) => rename::handle(config, mega, opts).await,
Command::Delete(opts) => delete::handle(config, mega, opts).await,
Command::Follow(opts) => follow::handle(config, mega, opts).await,
Command::Compare(opts) => compare::handle(config, mega, opts).await,
}
}