summaryrefslogtreecommitdiff
path: root/src/commands/mod.rs
blob: 7f466f92ba2707b2546238d7dc27b1522b42623e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use clap::Subcommand;

pub mod completions;
pub mod list;
pub mod mount;
pub mod subvolume;

pub use completions::completions;
pub use list::list;
pub use mount::mount;
pub use subvolume::subvolume;

#[derive(clap::Parser, Debug)]
#[command(name = "bcachefs")]
pub struct Cli {
    #[command(subcommand)]
    subcommands: Subcommands,
}

#[derive(Subcommand, Debug)]
enum Subcommands {
    List(list::Cli),
    Mount(mount::Cli),
    Completions(completions::Cli),
    #[command(visible_aliases = ["subvol"])]
    Subvolume(subvolume::Cli),
}

// FIXME: Can be removed after bumping MSRV >= 1.77 in favor of `c""` literals
#[macro_export]
macro_rules! c_str {
    ($lit:expr) => {
        ::std::ffi::CStr::from_bytes_with_nul(concat!($lit, "\0").as_bytes())
            .unwrap()
            .as_ptr()
    };
}

#[cfg(test)]
mod tests {
    use std::ffi::CStr;

    #[test]
    fn check_cstr_macro() {
        let literal = c_str!("hello");

        assert_eq!(
            literal,
            CStr::from_bytes_with_nul(b"hello\0").unwrap().as_ptr()
        );
    }
}