Prepare for clap 4.
Bug: 260823636
Test: atest vm.test encryptedstore.test apkdmverity.test open_then_run.test ZipFuseTest
Change-Id: Iba2c4c317e7e42fc99362caf41ab083b4fc4a8db
diff --git a/encryptedstore/src/main.rs b/encryptedstore/src/main.rs
index 7140ae2..888485b 100644
--- a/encryptedstore/src/main.rs
+++ b/encryptedstore/src/main.rs
@@ -19,9 +19,8 @@
//! It uses dm_rust lib.
use anyhow::{ensure, Context, Result};
-use clap::{arg, App};
-use dm::crypt::CipherType;
-use dm::util;
+use clap::arg;
+use dm::{crypt::CipherType, util};
use log::info;
use std::ffi::CString;
use std::fs::{create_dir_all, OpenOptions};
@@ -42,18 +41,11 @@
);
info!("Starting encryptedstore binary");
- let matches = App::new("encryptedstore")
- .args(&[
- arg!(--blkdevice <FILE> "the block device backing the encrypted storage")
- .required(true),
- arg!(--key <KEY> "key (in hex) equivalent to 32 bytes)").required(true),
- arg!(--mountpoint <MOUNTPOINT> "mount point for the storage").required(true),
- ])
- .get_matches();
+ let matches = clap_command().get_matches();
- let blkdevice = Path::new(matches.value_of("blkdevice").unwrap());
- let key = matches.value_of("key").unwrap();
- let mountpoint = Path::new(matches.value_of("mountpoint").unwrap());
+ let blkdevice = Path::new(matches.get_one::<String>("blkdevice").unwrap());
+ let key = matches.get_one::<String>("key").unwrap();
+ let mountpoint = Path::new(matches.get_one::<String>("mountpoint").unwrap());
encryptedstore_init(blkdevice, key, mountpoint).context(format!(
"Unable to initialize encryptedstore on {:?} & mount at {:?}",
blkdevice, mountpoint
@@ -61,6 +53,14 @@
Ok(())
}
+fn clap_command() -> clap::Command {
+ clap::Command::new("encryptedstore").args(&[
+ arg!(--blkdevice <FILE> "the block device backing the encrypted storage").required(true),
+ arg!(--key <KEY> "key (in hex) equivalent to 32 bytes)").required(true),
+ arg!(--mountpoint <MOUNTPOINT> "mount point for the storage").required(true),
+ ])
+}
+
fn encryptedstore_init(blkdevice: &Path, key: &str, mountpoint: &Path) -> Result<()> {
ensure!(
std::fs::metadata(&blkdevice)
@@ -160,3 +160,14 @@
Ok(())
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn verify_command() {
+ // Check that the command parsing has been configured in a valid way.
+ clap_command().debug_assert();
+ }
+}