raws_ec2/
lib.rs

1use aws_sdk_ec2 as ec2;
2use clap::{Args, Subcommand};
3use ec2::types;
4
5use config::Config;
6use error::RawsError;
7
8mod vpc;
9
10type Ec2Result<T = Box<dyn show::Show>> = Result<T, ec2::Error>;
11
12/// Amazon Elastic Compute Cloud (Amazon EC2) provides secure and resizable
13/// computing capacity in the Amazon Web Services Cloud.
14#[derive(Debug, Subcommand)]
15#[allow(clippy::large_enum_variant)]
16pub enum Ec2 {
17    CreateVpc(vpc::CreateVpc),
18    DeleteVpc(vpc::DeleteVpc),
19    DescribeVpcs(vpc::DescribeVpcs),
20}
21
22impl Ec2 {
23    async fn execute(self, config: &Config) -> Ec2Result {
24        match self {
25            Self::CreateVpc(create_vpc) => create_vpc.execute(config).await,
26            Self::DeleteVpc(delete_vpc) => delete_vpc.execute(config).await,
27            Self::DescribeVpcs(describe_vpcs) => describe_vpcs.execute(config).await,
28        }
29    }
30
31    pub async fn dispatch(self, config: Config) -> Result<(), RawsError<ec2::Error>> {
32        self.execute(&config)
33            .await
34            .map(|output| config.show(output))?;
35        Ok(())
36    }
37}