summaryrefslogtreecommitdiff
path: root/rust-src/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rust-src/src/lib.rs')
-rw-r--r--rust-src/src/lib.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/rust-src/src/lib.rs b/rust-src/src/lib.rs
index 159d049d..64297b41 100644
--- a/rust-src/src/lib.rs
+++ b/rust-src/src/lib.rs
@@ -1,7 +1,24 @@
+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 {
@@ -14,6 +31,18 @@ macro_rules! c_str {
};
}
+#[macro_export]
+macro_rules! transform_c_args {
+ ($var:ident, $argc:expr, $argv:expr) => {
+ // TODO: `OsStr::from_bytes` only exists on *nix
+ use ::std::os::unix::ffi::OsStrExt;
+ let $var: Vec<_> = (0..$argc)
+ .map(|i| unsafe { ::std::ffi::CStr::from_ptr(*$argv.add(i as usize)) })
+ .map(|i| ::std::ffi::OsStr::from_bytes(i.to_bytes()))
+ .collect();
+ };
+}
+
#[derive(Debug)]
struct ErrnoError(errno::Errno);
impl std::fmt::Display for ErrnoError {