Skip to main content

btrfs_cli/
device.rs

1use crate::{Format, Runnable};
2use anyhow::Result;
3use clap::Parser;
4
5mod add;
6mod ready;
7mod remove;
8mod scan;
9mod stats;
10mod usage;
11
12pub use self::{add::*, ready::*, remove::*, scan::*, stats::*, usage::*};
13
14/// Manage devices in a btrfs filesystem.
15///
16/// Perform operations on block devices that are part of a btrfs filesystem,
17/// including adding and removing devices, viewing device statistics, and
18/// checking device readiness. Most operations require CAP_SYS_ADMIN.
19#[derive(Parser, Debug)]
20#[allow(clippy::doc_markdown)]
21pub struct DeviceCommand {
22    #[clap(subcommand)]
23    pub subcommand: DeviceSubcommand,
24}
25
26impl Runnable for DeviceCommand {
27    fn run(&self, format: Format, dry_run: bool) -> Result<()> {
28        match &self.subcommand {
29            DeviceSubcommand::Add(cmd) => cmd.run(format, dry_run),
30            DeviceSubcommand::Remove(cmd) | DeviceSubcommand::Delete(cmd) => {
31                cmd.run(format, dry_run)
32            }
33            DeviceSubcommand::Stats(cmd) => cmd.run(format, dry_run),
34            DeviceSubcommand::Scan(cmd) => cmd.run(format, dry_run),
35            DeviceSubcommand::Ready(cmd) => cmd.run(format, dry_run),
36            DeviceSubcommand::Usage(cmd) => cmd.run(format, dry_run),
37        }
38    }
39}
40
41#[derive(Parser, Debug)]
42pub enum DeviceSubcommand {
43    Add(DeviceAddCommand),
44    Remove(DeviceRemoveCommand),
45    #[clap(alias = "del")]
46    Delete(DeviceRemoveCommand),
47    Stats(DeviceStatsCommand),
48    Scan(DeviceScanCommand),
49    Ready(DeviceReadyCommand),
50    Usage(DeviceUsageCommand),
51}