pub mod commands;
use crate::error::Result;
use clap::{Args, Parser, Subcommand};
use std::path::PathBuf;
#[derive(Subcommand, Debug, PartialEq)]
pub enum ConfigCommand {
Show,
Edit,
Set(ConfigSetArgs),
DirAdd(DirectoryAddArgs),
DirRm(DirectoryRemoveArgs),
}
#[derive(Args, Debug, PartialEq)]
pub struct ConfigSetArgs {
#[arg(long)]
pub endpoint: Option<String>,
#[arg(long)]
pub bucket: Option<String>,
#[arg(long)]
pub region: Option<String>,
#[arg(long)]
pub force_path_style: Option<bool>,
#[arg(long)]
pub part_size: Option<u64>,
#[arg(long)]
pub local_directory_path: Option<PathBuf>,
}
#[derive(Args, Debug, PartialEq)]
pub struct DirectoryAddArgs {
pub local_name_prefix: String,
pub remote_path: String,
}
#[derive(Args, Debug, PartialEq)]
pub struct DirectoryRemoveArgs {
pub local_name_prefix: String,
}
#[derive(Subcommand, Debug, PartialEq)]
pub enum Commands {
Config {
#[command(subcommand)]
command: ConfigCommand,
},
Login,
Run {
#[arg(short, long, default_value_t = false)]
quiet: bool,
},
Schedule { cron: String },
}
#[derive(Parser, Debug, PartialEq)]
#[command(name = "prefixload")]
#[command(about = "S3 cli backup by file name prefix")]
#[command(version)]
pub struct Cli {
#[command(subcommand)]
command: Commands,
}
impl Cli {
pub async fn run(self) -> Result<String> {
match self.command {
Commands::Config { command } => commands::config::run(command).await,
Commands::Login => commands::login::run().await,
Commands::Run { quiet } => commands::run::run(quiet).await,
Commands::Schedule { cron } => commands::schedule::run(cron.as_ref()).await,
}
}
pub fn get_command(&self) -> &Commands {
&self.command
}
}