raws_s3/
lib.rs

1use aws_sdk_s3 as s3;
2use clap::{Args, Subcommand};
3
4use config::Config;
5use error::RawsError;
6
7use self::client::S3Client;
8use self::ext::bucket_name;
9use self::ext::maybe_bucket_name;
10
11mod bucket;
12mod client;
13mod ext;
14
15type S3Result<T = Box<dyn show::Show>> = Result<T, s3::Error>;
16
17const S3_PREFIX: &str = "s3://";
18
19/// High-level S3 commands
20#[derive(Debug, Subcommand)]
21pub enum S3 {
22    Mb(bucket::Make),
23    Rb(bucket::Remove),
24    Ls(bucket::List),
25}
26
27impl S3 {
28    async fn execute(self, config: &Config) -> S3Result {
29        match self {
30            Self::Mb(mb) => mb.execute(config).await,
31            Self::Rb(rb) => rb.execute(config).await,
32            Self::Ls(ls) => ls.execute(config).await,
33        }
34    }
35
36    pub async fn dispatch(self, config: Config) -> Result<(), RawsError<s3::Error>> {
37        self.execute(&config)
38            .await
39            .map(|output| config.show(output))?;
40        Ok(())
41    }
42}