diff options
author | Zhai Can <bczhc0@126.com> | 2023-11-10 20:13:03 +0800 |
---|---|---|
committer | Zhai Can <bczhc0@126.com> | 2023-11-10 21:20:01 +0800 |
commit | 1d1fe7b0b68719263ea31504e74c2b0f5ad2e053 (patch) | |
tree | 7679e8685b022b35371389f298aab6557bffa923 /rust-src/src/lib.rs | |
parent | 61134a06fa714f32a405680d3515af94dfa11d2c (diff) |
add command to generate Rust-part CLI completions
Diffstat (limited to 'rust-src/src/lib.rs')
-rw-r--r-- | rust-src/src/lib.rs | 29 |
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 { |