Merge changes from topic "aconfig-part-3"

* changes:
  aconfig: simplify argument parsing in main
  aconfig: improve flag value tracing
diff --git a/tools/aconfig/src/cache.rs b/tools/aconfig/src/cache.rs
index 20c5de5..94443d7 100644
--- a/tools/aconfig/src/cache.rs
+++ b/tools/aconfig/src/cache.rs
@@ -22,12 +22,19 @@
 use crate::commands::Source;
 
 #[derive(Serialize, Deserialize, Debug)]
+pub struct TracePoint {
+    pub source: Source,
+    pub state: FlagState,
+    pub permission: Permission,
+}
+
+#[derive(Serialize, Deserialize, Debug)]
 pub struct Item {
     pub id: String,
     pub description: String,
     pub state: FlagState,
     pub permission: Permission,
-    pub debug: Vec<String>,
+    pub trace: Vec<TracePoint>,
 }
 
 #[derive(Serialize, Deserialize, Debug)]
@@ -63,7 +70,7 @@
             description: flag.description,
             state,
             permission,
-            debug: vec![format!("{}:{:?} {:?}", source, state, permission)],
+            trace: vec![TracePoint { source, state, permission }],
         });
         Ok(())
     }
@@ -74,9 +81,11 @@
         };
         existing_item.state = override_.state;
         existing_item.permission = override_.permission;
-        existing_item
-            .debug
-            .push(format!("{}:{:?} {:?}", source, override_.state, override_.permission));
+        existing_item.trace.push(TracePoint {
+            source,
+            state: override_.state,
+            permission: override_.permission,
+        });
         Ok(())
     }
 
diff --git a/tools/aconfig/src/commands.rs b/tools/aconfig/src/commands.rs
index dc3e6bc..73d3357 100644
--- a/tools/aconfig/src/commands.rs
+++ b/tools/aconfig/src/commands.rs
@@ -16,13 +16,14 @@
 
 use anyhow::{Context, Result};
 use clap::ValueEnum;
+use serde::{Deserialize, Serialize};
 use std::fmt;
 use std::io::Read;
 
 use crate::aconfig::{Flag, Override};
 use crate::cache::Cache;
 
-#[derive(Clone)]
+#[derive(Serialize, Deserialize, Clone, Debug)]
 pub enum Source {
     #[allow(dead_code)] // only used in unit tests
     Memory,
diff --git a/tools/aconfig/src/main.rs b/tools/aconfig/src/main.rs
index 3ce9747..62750ae 100644
--- a/tools/aconfig/src/main.rs
+++ b/tools/aconfig/src/main.rs
@@ -17,7 +17,7 @@
 //! `aconfig` is a build time tool to manage build time configurations, such as feature flags.
 
 use anyhow::Result;
-use clap::{builder::ArgAction, builder::EnumValueParser, Arg, Command};
+use clap::{builder::ArgAction, builder::EnumValueParser, Arg, ArgMatches, Command};
 use std::fs;
 
 mod aconfig;
@@ -53,25 +53,22 @@
         )
 }
 
+fn open_zero_or_more_files(matches: &ArgMatches, arg_name: &str) -> Result<Vec<Input>> {
+    let mut opened_files = vec![];
+    for path in matches.get_many::<String>(arg_name).unwrap_or_default() {
+        let file = Box::new(fs::File::open(path)?);
+        opened_files.push(Input { source: Source::File(path.to_string()), reader: file });
+    }
+    Ok(opened_files)
+}
+
 fn main() -> Result<()> {
     let matches = cli().get_matches();
     match matches.subcommand() {
         Some(("create-cache", sub_matches)) => {
-            let mut aconfigs = vec![];
             let build_id = *sub_matches.get_one::<u32>("build-id").unwrap();
-            for path in
-                sub_matches.get_many::<String>("aconfig").unwrap_or_default().collect::<Vec<_>>()
-            {
-                let file = Box::new(fs::File::open(path)?);
-                aconfigs.push(Input { source: Source::File(path.to_string()), reader: file });
-            }
-            let mut overrides = vec![];
-            for path in
-                sub_matches.get_many::<String>("override").unwrap_or_default().collect::<Vec<_>>()
-            {
-                let file = Box::new(fs::File::open(path)?);
-                overrides.push(Input { source: Source::File(path.to_string()), reader: file });
-            }
+            let aconfigs = open_zero_or_more_files(sub_matches, "aconfig")?;
+            let overrides = open_zero_or_more_files(sub_matches, "override")?;
             let cache = commands::create_cache(build_id, aconfigs, overrides)?;
             let path = sub_matches.get_one::<String>("cache").unwrap();
             let file = fs::File::create(path)?;