mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-02-23 00:00:02 +03:00
This moves the main() function from C to Rust. It also updates the name of the Rust package from "bcachefs-rust" to "bcachefs-tools". Signed-off-by: Thomas Bertschinger <tahbertschinger@gmail.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
42 lines
923 B
Rust
42 lines
923 B
Rust
use clap::Subcommand;
|
|
|
|
pub mod key;
|
|
pub mod logger;
|
|
pub mod cmd_mount;
|
|
pub mod cmd_list;
|
|
pub mod cmd_completions;
|
|
|
|
#[derive(clap::Parser, Debug)]
|
|
#[command(name = "bcachefs")]
|
|
pub struct Cli {
|
|
#[command(subcommand)]
|
|
subcommands: Subcommands,
|
|
}
|
|
|
|
#[derive(Subcommand, Debug)]
|
|
enum Subcommands {
|
|
List(cmd_list::Cli),
|
|
Mount(cmd_mount::Cli),
|
|
Completions(cmd_completions::Cli),
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! c_str {
|
|
($lit:expr) => {
|
|
unsafe {
|
|
std::ffi::CStr::from_ptr(concat!($lit, "\0").as_ptr() as *const std::os::raw::c_char)
|
|
.to_bytes_with_nul()
|
|
.as_ptr() as *const std::os::raw::c_char
|
|
}
|
|
};
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
struct ErrnoError(errno::Errno);
|
|
impl std::fmt::Display for ErrnoError {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
|
|
self.0.fmt(f)
|
|
}
|
|
}
|
|
impl std::error::Error for ErrnoError {}
|