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/apkdmverity/src/main.rs b/apkdmverity/src/main.rs
index 6e12e38..50b6069 100644
--- a/apkdmverity/src/main.rs
+++ b/apkdmverity/src/main.rs
@@ -23,7 +23,7 @@
 
 use anyhow::{bail, Context, Result};
 use apkverify::{HashAlgorithm, V4Signature};
-use clap::{App, Arg};
+use clap::{arg, Arg, ArgAction, Command};
 use dm::loopdevice;
 use dm::util;
 use dm::verity::{DmVerityHashAlgorithm, DmVerityTargetBuilder};
@@ -34,22 +34,12 @@
 use std::path::{Path, PathBuf};
 
 fn main() -> Result<()> {
-    let matches = App::new("apkdmverity")
-        .about("Creates a dm-verity block device out of APK signed with APK signature scheme V4.")
-        .arg(Arg::from_usage(
-            "--apk... <apk_path> <idsig_path> <name> <root_hash> \
-                            'Input APK file, idsig file, name of the block device, and root hash. \
-                            The APK file must be signed using the APK signature scheme 4. The \
-                            block device is created at \"/dev/mapper/<name>\".' root_hash is \
-                            optional; idsig file's root hash will be used if specified as \"none\"."
-            ))
-        .arg(Arg::with_name("verbose").short('v').long("verbose").help("Shows verbose output"))
-        .get_matches();
+    let matches = clap_command().get_matches();
 
-    let apks = matches.values_of("apk").unwrap();
+    let apks = matches.get_many::<String>("apk").unwrap();
     assert!(apks.len() % 4 == 0);
 
-    let verbose = matches.is_present("verbose");
+    let verbose = matches.get_flag("verbose");
 
     for (apk, idsig, name, roothash) in apks.tuples() {
         let roothash = if roothash != "none" {
@@ -68,6 +58,28 @@
     Ok(())
 }
 
+fn clap_command() -> Command {
+    Command::new("apkdmverity")
+        .about("Creates a dm-verity block device out of APK signed with APK signature scheme V4.")
+        .arg(
+            arg!(--apk ...
+                "Input APK file, idsig file, name of the block device, and root hash. \
+                The APK file must be signed using the APK signature scheme 4. The \
+                block device is created at \"/dev/mapper/<name>\".' root_hash is \
+                optional; idsig file's root hash will be used if specified as \"none\"."
+            )
+            .action(ArgAction::Append)
+            .value_names(&["apk_path", "idsig_path", "name", "root_hash"]),
+        )
+        .arg(
+            Arg::new("verbose")
+                .short('v')
+                .long("verbose")
+                .action(ArgAction::SetTrue)
+                .help("Shows verbose output"),
+        )
+}
+
 struct VerityResult {
     data_device: PathBuf,
     hash_device: PathBuf,
@@ -380,4 +392,10 @@
             },
         );
     }
+
+    #[test]
+    fn verify_command() {
+        // Check that the command parsing has been configured in a valid way.
+        clap_command().debug_assert();
+    }
 }