Skip to main content

btrfs_cli/
subvolume.rs

1use crate::{CommandGroup, Runnable};
2use clap::Parser;
3
4mod create;
5mod delete;
6mod find_new;
7mod flags;
8mod get_default;
9mod list;
10mod set_default;
11mod show;
12mod snapshot;
13mod sync;
14
15pub use self::{
16    create::*, delete::*, find_new::*, flags::*, get_default::*, list::*,
17    set_default::*, show::*, snapshot::*, sync::*,
18};
19
20/// Create, delete, list, and manage btrfs subvolumes and snapshots.
21///
22/// Subvolumes are independent filesystem trees within a btrfs filesystem,
23/// allowing flexible storage organization, snapshots, and quota management.
24/// Snapshots are read-only or read-write copies of subvolumes at a point in time.
25/// Most operations require CAP_SYS_ADMIN.
26#[derive(Parser, Debug)]
27#[allow(clippy::doc_markdown)]
28#[clap(arg_required_else_help = true)]
29pub struct SubvolumeCommand {
30    #[clap(subcommand)]
31    pub subcommand: SubvolumeSubcommand,
32}
33
34impl CommandGroup for SubvolumeCommand {
35    fn leaf(&self) -> &dyn Runnable {
36        match &self.subcommand {
37            SubvolumeSubcommand::Create(cmd) => cmd,
38            SubvolumeSubcommand::Delete(cmd) => cmd,
39            SubvolumeSubcommand::Snapshot(cmd) => cmd,
40            SubvolumeSubcommand::Show(cmd) => cmd,
41            SubvolumeSubcommand::List(cmd) => cmd,
42            SubvolumeSubcommand::GetDefault(cmd) => cmd,
43            SubvolumeSubcommand::SetDefault(cmd) => cmd,
44            SubvolumeSubcommand::GetFlags(cmd) => cmd,
45            SubvolumeSubcommand::SetFlags(cmd) => cmd,
46            SubvolumeSubcommand::FindNew(cmd) => cmd,
47            SubvolumeSubcommand::Sync(cmd) => cmd,
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}