Merge changes from topic "aconfig-part-3"
* changes: aconfig: simplify argument parsing in main aconfig: improve flag value tracing
This commit is contained in:
@@ -21,13 +21,20 @@ use std::io::{Read, Write};
|
|||||||
use crate::aconfig::{Flag, FlagState, Override, Permission};
|
use crate::aconfig::{Flag, FlagState, Override, Permission};
|
||||||
use crate::commands::Source;
|
use crate::commands::Source;
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct TracePoint {
|
||||||
|
pub source: Source,
|
||||||
|
pub state: FlagState,
|
||||||
|
pub permission: Permission,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct Item {
|
pub struct Item {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub description: String,
|
pub description: String,
|
||||||
pub state: FlagState,
|
pub state: FlagState,
|
||||||
pub permission: Permission,
|
pub permission: Permission,
|
||||||
pub debug: Vec<String>,
|
pub trace: Vec<TracePoint>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
@@ -63,7 +70,7 @@ impl Cache {
|
|||||||
description: flag.description,
|
description: flag.description,
|
||||||
state,
|
state,
|
||||||
permission,
|
permission,
|
||||||
debug: vec![format!("{}:{:?} {:?}", source, state, permission)],
|
trace: vec![TracePoint { source, state, permission }],
|
||||||
});
|
});
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -74,9 +81,11 @@ impl Cache {
|
|||||||
};
|
};
|
||||||
existing_item.state = override_.state;
|
existing_item.state = override_.state;
|
||||||
existing_item.permission = override_.permission;
|
existing_item.permission = override_.permission;
|
||||||
existing_item
|
existing_item.trace.push(TracePoint {
|
||||||
.debug
|
source,
|
||||||
.push(format!("{}:{:?} {:?}", source, override_.state, override_.permission));
|
state: override_.state,
|
||||||
|
permission: override_.permission,
|
||||||
|
});
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,13 +16,14 @@
|
|||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use clap::ValueEnum;
|
use clap::ValueEnum;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
|
||||||
use crate::aconfig::{Flag, Override};
|
use crate::aconfig::{Flag, Override};
|
||||||
use crate::cache::Cache;
|
use crate::cache::Cache;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||||
pub enum Source {
|
pub enum Source {
|
||||||
#[allow(dead_code)] // only used in unit tests
|
#[allow(dead_code)] // only used in unit tests
|
||||||
Memory,
|
Memory,
|
||||||
|
@@ -17,7 +17,7 @@
|
|||||||
//! `aconfig` is a build time tool to manage build time configurations, such as feature flags.
|
//! `aconfig` is a build time tool to manage build time configurations, such as feature flags.
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::{builder::ArgAction, builder::EnumValueParser, Arg, Command};
|
use clap::{builder::ArgAction, builder::EnumValueParser, Arg, ArgMatches, Command};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
mod aconfig;
|
mod aconfig;
|
||||||
@@ -53,25 +53,22 @@ fn cli() -> Command {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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<()> {
|
fn main() -> Result<()> {
|
||||||
let matches = cli().get_matches();
|
let matches = cli().get_matches();
|
||||||
match matches.subcommand() {
|
match matches.subcommand() {
|
||||||
Some(("create-cache", sub_matches)) => {
|
Some(("create-cache", sub_matches)) => {
|
||||||
let mut aconfigs = vec![];
|
|
||||||
let build_id = *sub_matches.get_one::<u32>("build-id").unwrap();
|
let build_id = *sub_matches.get_one::<u32>("build-id").unwrap();
|
||||||
for path in
|
let aconfigs = open_zero_or_more_files(sub_matches, "aconfig")?;
|
||||||
sub_matches.get_many::<String>("aconfig").unwrap_or_default().collect::<Vec<_>>()
|
let overrides = open_zero_or_more_files(sub_matches, "override")?;
|
||||||
{
|
|
||||||
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 cache = commands::create_cache(build_id, aconfigs, overrides)?;
|
let cache = commands::create_cache(build_id, aconfigs, overrides)?;
|
||||||
let path = sub_matches.get_one::<String>("cache").unwrap();
|
let path = sub_matches.get_one::<String>("cache").unwrap();
|
||||||
let file = fs::File::create(path)?;
|
let file = fs::File::create(path)?;
|
||||||
|
Reference in New Issue
Block a user