Skip to main content

btrfs_cli/
replace.rs

1use crate::{Format, Runnable};
2use anyhow::Result;
3use clap::Parser;
4
5mod cancel;
6mod start;
7mod status;
8
9pub use self::{cancel::*, start::*, status::*};
10
11/// Replace a device in the filesystem.
12///
13/// Replace a device with another device or a spare. During replacement,
14/// data is read from the old device and written to the new one. The replace
15/// operation can be monitored and cancelled. Requires CAP_SYS_ADMIN.
16#[derive(Parser, Debug)]
17#[allow(clippy::doc_markdown)]
18pub struct ReplaceCommand {
19    #[clap(subcommand)]
20    pub subcommand: ReplaceSubcommand,
21}
22
23impl Runnable for ReplaceCommand {
24    fn run(&self, format: Format, dry_run: bool) -> Result<()> {
25        match &self.subcommand {
26            ReplaceSubcommand::Start(cmd) => cmd.run(format, dry_run),
27            ReplaceSubcommand::Status(cmd) => cmd.run(format, dry_run),
28            ReplaceSubcommand::Cancel(cmd) => cmd.run(format, dry_run),
29        }
30    }
31}
32
33#[derive(Parser, Debug)]
34pub enum ReplaceSubcommand {
35    Start(ReplaceStartCommand),
36    Status(ReplaceStatusCommand),
37    Cancel(ReplaceCancelCommand),
38}