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