1use aws_sdk_ebs as ebs;
2use clap::{Args, Subcommand};
3
4use config::Config;
5use error::RawsError;
6
7mod block;
8mod snapshot;
9
10type EbsResult<T = Box<dyn show::Show>> = Result<T, ebs::Error>;
11
12#[derive(Debug, Subcommand)]
15pub enum Ebs {
16 CompleteSnapshot(snapshot::CompleteSnapshot),
17 StartSnapshot(snapshot::StartSnapshot),
18 ListSnapshotBlocks(snapshot::ListSnapshotBlocks),
19 ListChangedBlocks(snapshot::ListChangedBlocks),
20 GetSnapshotBlock(block::GetSnapshotBlock),
21 PutSnapshotBlock(block::PutSnapshotBlock),
22}
23
24impl Ebs {
25 async fn execute(self, config: &Config) -> EbsResult {
26 match self {
27 Self::CompleteSnapshot(complete_snapshot) => complete_snapshot.execute(config).await,
28 Self::StartSnapshot(start_snapshot) => start_snapshot.execute(config).await,
29 Self::ListSnapshotBlocks(list_snapshot_blocks) => {
30 list_snapshot_blocks.execute(config).await
31 }
32 Self::ListChangedBlocks(list_changed_blocks) => {
33 list_changed_blocks.execute(config).await
34 }
35 Self::GetSnapshotBlock(get_snapshot_block) => get_snapshot_block.execute(config).await,
36 Self::PutSnapshotBlock(put_snapshot_block) => put_snapshot_block.execute(config).await,
37 }
38 }
39
40 pub async fn dispatch(self, config: Config) -> Result<(), RawsError<ebs::Error>> {
41 self.execute(&config)
42 .await
43 .map(|output| config.show(output))?;
44 Ok(())
45 }
46}