Skip to main content

btrfs_cli/
subvolume.rs

1use crate::{Format, Runnable};
2use anyhow::Result;
3use clap::Parser;
4
5mod create;
6mod delete;
7mod find_new;
8mod flags;
9mod get_default;
10mod list;
11mod set_default;
12mod show;
13mod snapshot;
14mod sync;
15
16pub use self::{
17    create::*, delete::*, find_new::*, flags::*, get_default::*, list::*,
18    set_default::*, show::*, snapshot::*, sync::*,
19};
20
21/// Create, delete, list, and manage btrfs subvolumes and snapshots.
22///
23/// Subvolumes are independent filesystem trees within a btrfs filesystem,
24/// allowing flexible storage organization, snapshots, and quota management.
25/// Snapshots are read-only or read-write copies of subvolumes at a point in time.
26/// Most operations require CAP_SYS_ADMIN.
27#[derive(Parser, Debug)]
28#[allow(clippy::doc_markdown)]
29pub struct SubvolumeCommand {
30    #[clap(subcommand)]
31    pub subcommand: SubvolumeSubcommand,
32}
33
34impl Runnable for SubvolumeCommand {
35    fn run(&self, format: Format, dry_run: bool) -> Result<()> {
36        match &self.subcommand {
37            SubvolumeSubcommand::Create(cmd) => cmd.run(format, dry_run),
38            SubvolumeSubcommand::Delete(cmd) => cmd.run(format, dry_run),
39            SubvolumeSubcommand::Snapshot(cmd) => cmd.run(format, dry_run),
40            SubvolumeSubcommand::Show(cmd) => cmd.run(format, dry_run),
41            SubvolumeSubcommand::List(cmd) => cmd.run(format, dry_run),
42            SubvolumeSubcommand::GetDefault(cmd) => cmd.run(format, dry_run),
43            SubvolumeSubcommand::SetDefault(cmd) => cmd.run(format, dry_run),
44            SubvolumeSubcommand::GetFlags(cmd) => cmd.run(format, dry_run),
45            SubvolumeSubcommand::SetFlags(cmd) => cmd.run(format, dry_run),
46            SubvolumeSubcommand::FindNew(cmd) => cmd.run(format, dry_run),
47            SubvolumeSubcommand::Sync(cmd) => cmd.run(format, dry_run),
48        }
49    }
50}
51
52#[derive(Parser, Debug)]
53pub enum SubvolumeSubcommand {
54    Create(SubvolumeCreateCommand),
55    #[clap(alias = "del")]
56    Delete(SubvolumeDeleteCommand),
57    Snapshot(SubvolumeSnapshotCommand),
58    Show(SubvolumeShowCommand),
59    List(SubvolumeListCommand),
60    GetDefault(SubvolumeGetDefaultCommand),
61    SetDefault(SubvolumeSetDefaultCommand),
62    GetFlags(SubvolumeGetFlagsCommand),
63    SetFlags(SubvolumeSetFlagsCommand),
64    FindNew(SubvolumeFindNewCommand),
65    Sync(SubvolumeSyncCommand),
66}