btrfs_cli/property/
list.rs1use super::{
2 PropertyObjectType, detect_object_types, property_description,
3 property_names,
4};
5use crate::{Format, Runnable};
6use anyhow::{Result, anyhow, bail};
7use clap::Parser;
8use std::path::PathBuf;
9
10#[derive(Parser, Debug)]
12pub struct PropertyListCommand {
13 pub object: PathBuf,
15
16 #[clap(short = 't', long = "type")]
18 pub object_type: Option<PropertyObjectType>,
19}
20
21impl Runnable for PropertyListCommand {
22 fn run(&self, _format: Format, _dry_run: bool) -> Result<()> {
23 let detected_types = detect_object_types(&self.object);
25 let target_type = match self.object_type {
26 Some(t) => t,
27 None => {
28 if detected_types.len() > 1 {
30 bail!(
31 "object type is ambiguous, please use option -t (detected: {:?})",
32 detected_types
33 );
34 }
35 detected_types
36 .first()
37 .copied()
38 .ok_or_else(|| anyhow!("object is not a btrfs object"))?
39 }
40 };
41
42 for name in property_names(target_type) {
43 println!("{:<20}{}", name, property_description(name));
44 }
45
46 Ok(())
47 }
48}