wasmer_cli/
opts.rs

1use crate::utils::render::ItemFormat;
2
3/// Formatting options for a single item.
4#[derive(clap::Parser, Debug, Default)]
5pub struct ItemFormatOpts {
6    /// Output format. (yaml, json, table)
7    ///
8    /// This value is optional instead of using a default value to allow code
9    /// to distinguish between the user not specifying a value and a generic
10    /// default.
11    ///
12    /// Code should usually use [`Self::get`] to use the same default format.
13    #[clap(short = 'f', long)]
14    pub format: Option<ItemFormat>,
15}
16
17impl ItemFormatOpts {
18    /// Get the output format, defaulting to `ItemFormat::Yaml`.
19    pub fn get(&self) -> crate::utils::render::ItemFormat {
20        self.format
21            .unwrap_or(crate::utils::render::ItemFormat::Table)
22    }
23
24    /// Get the output format, defaulting to the given value if not specified.
25    pub fn get_with_default(&self, default: ItemFormat) -> crate::utils::render::ItemFormat {
26        self.format.unwrap_or(default)
27    }
28}
29
30/// Formatting options for a single item.
31#[derive(clap::Parser, Debug, Default)]
32pub struct ItemTableFormatOpts {
33    /// Output format. (yaml, json, table)
34    #[clap(short = 'f', long, default_value = "table")]
35    pub format: crate::utils::render::ItemFormat,
36}
37
38/// Formatting options for a list of items.
39#[derive(clap::Parser, Debug)]
40pub struct ListFormatOpts {
41    /// Output format. (yaml, json, table, item-table)
42    #[clap(short = 'f', long, default_value = "table")]
43    pub format: crate::utils::render::ListFormat,
44}