btrfs_cli/property/
list.rs1use super::{
2 PropertyObjectType, detect_object_types, property_description,
3 property_names,
4};
5use crate::{RunContext, 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, _ctx: &RunContext) -> Result<()> {
23 let detected_types = detect_object_types(&self.object);
25 let target_type = if let Some(t) = self.object_type {
26 t
27 } else {
28 if detected_types.len() > 1 {
30 bail!(
31 "object type is ambiguous, please use option -t (detected: {detected_types:?})"
32 );
33 }
34 detected_types
35 .first()
36 .copied()
37 .ok_or_else(|| anyhow!("object is not a btrfs object"))?
38 };
39
40 for name in property_names(target_type) {
41 println!("{:<20}{}", name, property_description(name));
42 }
43
44 Ok(())
45 }
46}