use super::{
PropertyObjectType, detect_object_types, property_description,
property_names,
};
use crate::{RunContext, Runnable};
use anyhow::{Result, anyhow, bail};
use clap::Parser;
use std::path::PathBuf;
#[derive(Parser, Debug)]
pub struct PropertyListCommand {
pub object: PathBuf,
#[clap(short = 't', long = "type")]
pub object_type: Option<PropertyObjectType>,
}
impl Runnable for PropertyListCommand {
fn run(&self, _ctx: &RunContext) -> Result<()> {
let detected_types = detect_object_types(&self.object);
let target_type = if let Some(t) = self.object_type {
t
} else {
if detected_types.len() > 1 {
bail!(
"object type is ambiguous, please use option -t (detected: {detected_types:?})"
);
}
detected_types
.first()
.copied()
.ok_or_else(|| anyhow!("object is not a btrfs object"))?
};
for name in property_names(target_type) {
println!("{:<20}{}", name, property_description(name));
}
Ok(())
}
}