Merge "aconfig: update aconfig_storage_file crate" into main

This commit is contained in:
Dennis Shen
2024-03-08 13:33:37 +00:00
committed by Gerrit Code Review
4 changed files with 25 additions and 11 deletions

View File

@@ -6,7 +6,6 @@ rust_defaults {
name: "aconfig_storage_file.defaults",
edition: "2021",
lints: "none",
srcs: ["src/lib.rs"],
rustlibs: [
"libanyhow",
"libthiserror",
@@ -22,12 +21,21 @@ rust_library {
crate_name: "aconfig_storage_file",
host_supported: true,
defaults: ["aconfig_storage_file.defaults"],
srcs: ["src/lib.rs"],
}
rust_binary_host {
name: "aconfig-storage",
defaults: ["aconfig_storage_file.defaults"],
srcs: ["src/main.rs"],
rustlibs: ["libaconfig_storage_file"],
}
rust_test_host {
name: "aconfig_storage_file.test",
test_suites: ["general-tests"],
defaults: ["aconfig_storage_file.defaults"],
srcs: ["src/lib.rs"],
}
rust_protobuf {

View File

@@ -14,6 +14,10 @@ tempfile = "3.9.0"
thiserror = "1.0.56"
clap = { version = "4.1.8", features = ["derive"] }
[[bin]]
name = "aconfig-storage"
path = "src/main.rs"
[build-dependencies]
protobuf-codegen = "3.2.0"
cxx-build = "1.0"

View File

@@ -78,7 +78,9 @@ impl TryFrom<&str> for StorageFileSelection {
"package_map" => Ok(Self::PackageMap),
"flag_map" => Ok(Self::FlagMap),
"flag_val" => Ok(Self::FlagVal),
_ => Err(anyhow!("Invalid storage file to create")),
_ => Err(anyhow!(
"Invalid storage file type, valid types are package_map|flag_map|flag_val]"
)),
}
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
//! `aconfig_storage` is a debugging tool to parse storage files
//! `aconfig-storage` is a debugging tool to parse storage files
use aconfig_storage_file::{
list_flags, read_file_to_bytes, AconfigStorageError, FlagTable, FlagValueList, PackageTable,
@@ -24,7 +24,7 @@ use aconfig_storage_file::{
use clap::{builder::ArgAction, Arg, Command};
fn cli() -> Command {
Command::new("aconfig_storage_file")
Command::new("aconfig-storage")
.subcommand_required(true)
.subcommand(
Command::new("print")
@@ -39,13 +39,13 @@ fn cli() -> Command {
.subcommand(
Command::new("list")
.arg(
Arg::new("package_map")
.long("package_map")
Arg::new("package-map")
.long("package-map")
.required(true)
.action(ArgAction::Set),
)
.arg(Arg::new("flag_map").long("flag_map").required(true).action(ArgAction::Set))
.arg(Arg::new("flag_val").long("flag_val").required(true).action(ArgAction::Set)),
.arg(Arg::new("flag-map").long("flag-map").required(true).action(ArgAction::Set))
.arg(Arg::new("flag-val").long("flag-val").required(true).action(ArgAction::Set)),
)
}
@@ -80,9 +80,9 @@ fn main() -> Result<(), AconfigStorageError> {
print_storage_file(file_path, file_type)?
}
Some(("list", sub_matches)) => {
let package_map = sub_matches.get_one::<String>("package_map").unwrap();
let flag_map = sub_matches.get_one::<String>("flag_map").unwrap();
let flag_val = sub_matches.get_one::<String>("flag_val").unwrap();
let package_map = sub_matches.get_one::<String>("package-map").unwrap();
let flag_map = sub_matches.get_one::<String>("flag-map").unwrap();
let flag_val = sub_matches.get_one::<String>("flag-val").unwrap();
let flags = list_flags(package_map, flag_map, flag_val)?;
for flag in flags.iter() {
println!("{}: {}", flag.0, flag.1);