-
Notifications
You must be signed in to change notification settings - Fork 198
/
list.rs
60 lines (53 loc) · 1.55 KB
/
list.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//!
//! # List All Spus CLI
//!
//! CLI tree and processing to list SPUs
//!
use std::sync::Arc;
use structopt::StructOpt;
use fluvio::Fluvio;
use fluvio_controlplane_metadata::spu::SpuSpec;
use fluvio::metadata::spu::CustomSpuSpec;
use fluvio::metadata::objects::Metadata;
use crate::cli::ClusterCliError;
use crate::cli::common::output::Terminal;
use crate::cli::common::OutputFormat;
use crate::cli::spu::display::format_spu_response_output;
#[derive(Debug, StructOpt)]
pub struct ListSpusOpt {
/// Whether to list only custom SPUs
#[structopt(long)]
custom: bool,
/// The output format to print the SPUs
#[structopt(flatten)]
output: OutputFormat,
}
impl ListSpusOpt {
/// Process list spus cli request
pub async fn process<O: Terminal>(
self,
out: Arc<O>,
fluvio: &Fluvio,
) -> Result<(), ClusterCliError> {
let admin = fluvio.admin().await;
let spus = if self.custom {
// List custom SPUs only
admin
.list::<CustomSpuSpec, _>(vec![])
.await?
.into_iter()
.map(|custom_spu| Metadata {
name: custom_spu.name,
spec: custom_spu.spec.into(),
status: custom_spu.status,
})
.collect()
} else {
// List all SPUs
admin.list::<SpuSpec, _>(vec![]).await?
};
// format and dump to screen
format_spu_response_output(out, spus, self.output.format)?;
Ok(())
}
}